Java Program to Print Right Angled Triangle with Increasing Alternate Case Character Pattern

Program to Print Right Angled Triangle with Increasing Alternate Case Character Pattern

In this program we are going to see how to print the right angled triangle with increasing alternate case character pattern.

Example-1

When starting character=h 
and row value=3

h
I j
k L m
Example-2:

When starting character=a 
and row value=5

a
B c
d E f
G h I j
k L m N o

Now, let’s see the actual program to print it.

Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well.

Approach:

  • Enter the character and store it in a variable c.
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a new line.

JAVA CODE:

import java.util.Scanner;
import java.lang.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed as input from the user
        System.out.print("First Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            //Outer loop to iterate rows
            for(row = 0; row<row_count; row++){
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++){
                    //Alternating the case in each iteration
                    if((row+col)%2==0)
                        System.out.print(Character.toLowerCase(c)+" ");
                    else
                        System.out.print(Character.toUpperCase(c)+" ");
                    //Incrementing the character
                    c++;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}
Output

First Character : a
Rows : 5

a
B c
d E f
G h I j
k L m N o

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("First Character : ");
    char c;
    scanf("%c", &c);

    //Taking number of rows as input from the user
    printf("Rows : ");
    int row_count;
    scanf("%d", &row_count);

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                //Alternating the case in each iteration
                if ((row + col) % 2 == 0)
                    printf("%c ", tolower(c));
                else
                    printf("%c ", toupper(c));
                //Incrementing the character
                c++;
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}
Output

First Character : a
Rows : 5

a
B c
d E f
G h I j
k L m N o

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "First Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                //Alternating the case in each iteration
                if ((row + col) % 2 == 0)
                    cout << (char)tolower(c) << " ";
                else
                    cout << (char)toupper(c) << " ";
                //Incrementing the character
                c++;
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:  First Character : a
Rows : 5

a
B c
d E f
G h I j
k L m N o

Related Java Star Pattern Programs:

Java Program to Print Equilateral Triangle Character Pattern

Program to Print Equilateral Triangle Character Pattern

In the previous article, we have discussed Java Program to Print Downward Triangle Character Pattern

In this program we are going to see how to print an equilateral triangle character pattern.

Example-1

When character=h 
and row value=3

   h
   i j
 k l m
Example-2:

When character=A 
and row value=5

      A
     B C
    D E F
   G H I J
 K L M N O

Now, let’s see the actual program to print it.

Access the Simple Java program for Interview examples with output from our page and impress your interviewer panel with your coding skills.

Approach:

  • Enter the character and store it in a variable c.
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a new line.

Java Code to Print Equilateral Triangle Character Pattern

import java.util.Scanner;
class Main
    {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed as input from the user
        System.out.print("Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            
            //Outer loop to iterate rows
            for (row = 0; row < row_count; row++)
            {
                //Inner loop to print space
                for (col = row_count; col >row; col--)
                {
                    System.out.print(" ");
                    
                }
                //Inner loop to print character
                for(col = 0; col<=row; col++)
                {
                    System.out.print(c+" ");
                    c++;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}

Output:

Character : A
Rows : 5

       A
     B C
    D E F
   G H  I  J
 K L M N O

C Code to Print Equilateral Triangle Character Pattern

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Character : ");
    char c;
    scanf("%c", &c);

    //Taking number of rows as input from the user
    printf("Rows : ");
    int row_count;
    scanf("%d", &row_count);

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to print space
            for (col = row_count; col > row; col--)
            {
                printf(" ");
            }
            //Inner loop to print character
            for (col = 0; col <= row; col++)
            {
                printf("%c ", c++);
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}
Output:

Character : A
Rows : 5

       A
     B  C
   D  E  F
  G  H  I  J
 K L M N O

C++ Code to Print Equilateral Triangle Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to print space
            for (col = row_count; col > row; col--)
            {
                cout << " ";
            }
            //Inner loop to print characters
            for (col = 0; col <= row; col++)
            {
                cout << c++ << " ";
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

       A
     B  C
   D  E  F
  G  H  I  J
 K L M N O

Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.

Related Java Character Pattern Programs:

Java Program to Print Right Angled Triangle with Decreasing Character Pattern

Program to Print Right Angled Triangle with Decreasing Character Pattern

In this program we are going to see how to print the right angled triangle with decreasing character pattern.

Example-1

When character=h & row value=3

h
g f
e d c
Example-2:

When character=z & row value=5

Z
Y X
W V U
T S R Q
P O N M L

Now, let’s see the actual program to print it.

Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.

Approach:

  • Enter the character and store it in a variable c
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a new line.

JAVA CODE:

import java.util.Scanner;
class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed as 
        // input from the user
        System.out.print("Last Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            //Outer loop to iterate rows
            for(row = 0; row<row_count; row++)
            {
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++)
                {
                    System.out.print(c+" ");
                    //Decrementing the character
                    c--;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}
Output:

Last Character : Z
Rows : 5

Z 
Y X 
W V U
T S R Q 
P O N M L

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Last Character : ");
    char c;
    scanf("%c", &c);

    //Taking number of rows as input from the user
    printf("Rows : ");
    int row_count;
    scanf("%d", &row_count);

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                printf("%c ", c);
                //Decrementing the character
                c--;
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}
Output:

Last Character : Z
Rows : 5

Z 
Y X 
W V U
T S R Q 
P O N M L

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Last Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << c << " ";
                //Decrementing the character
                c--;
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Last Character : Z
Rows : 5

Z 
Y X 
W V U
T S R Q 
P O N M L

Related Java Star Pattern Programs:

Java Program to Print Right Angled Triangle with Increasing Character Pattern

Program to Print Right Angled Triangle with Increasing Character Pattern

In this program we are going to see how to print the right angled triangle with increasing character pattern.

Example-1

When character=f & row value=3

f
g h
i   j  k
Example-2:

When character=a & row value=5

A
B C
D E F
G H I  J
K L M N O

Now, let’s see the actual program to print it.

If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list available.

Approach:

  • Enter the character and store it in a variable c, then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a newline.

JAVA CODE:

import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed as 
        // input from the user
        System.out.print("First Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            //Outer loop to iterate rows
            for(row = 0; row<row_count; row++)
            {
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++)
                {
                    System.out.print(c+" ");
                    //Incrementing the character
                    c++;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}
Output:

First Character : A
Rows : 5

A
B C
D E F
G H I J
K L M N O

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("First Character : ");
    char c;
    scanf("%c", &c);

    //Taking number of rows as input from the user
    printf("Rows : ");
    int row_count;
    scanf("%d", &row_count);

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                printf("%c ", c);
                //Incrementing the character
                c++;
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}

Output:

First Character : A
Rows : 5

A
B C
D E F
G H I J
K L M N O

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "First Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << c << " ";
                //Incrementing the character
                c++;
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}
Output:

First Character : A
Rows : 5

A
B C
D E F
G H I J
K L M N O

Related Java Star Pattern Programs:

Java Program to Print Downward Triangle Character Pattern

Program to Print Downward Triangle Character Pattern

In the previous article, we have discussed Java Program to Print Triangle with Repeated Character (Decreasing Order) Pattern

In this program we are going to see how to print downward triangle character pattern.

Example-1

When character=h 
and row value=3

   h i j
    h i
     h
Example-2:

When character=A 
and row value=5

  A B C D E
   A B C D
    A B C
     A B
      A

Now, let’s see the actual program to print it.

Interested in programming and want to excel in it by choosing the short ways. Then, practicing with the available Java Program list is mandatory.

Approach:

  • Enter the character and store it in a variable c.
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a new line.

Java to Print Downward Triangle Character Pattern

import java.util.Scanner;
class Main
{
public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    //Taking character to be printed as input from the user
    System.out.print("Character : ");
    char c = scan.next().charAt(0);

    //Taking number of rows as input from the user
    System.out.print("Rows : ");
    int row_count = scan.nextInt();

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int) c;

    //Checks whether the character is a letter or not
    if(asciiValue>=65&&asciiValue<=122)
    {
        
        //Outer loop to iterate rows
        for (row = 1; row <= row_count; row++)
        {
            //Inner loop to print space
            for (col = 0; col <=row; col++)
            {
                System.out.print(" ");
                
            }
            //Inner loop to print character
            for(col = 0; col<=row_count-row; col++)
            {
                System.out.print((char)(asciiValue+col)+" ");
            }
            //Prints a newline
            System.out.println();
        }
    }
}
}

Output:

Character : A
Rows : 5

A B C D E
  A B C D
   A B C
    A B
      A

C to Print Downward Triangle Character Pattern

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Character : ");
    char c;
    scanf("%c", &c);

    //Taking number of rows as input from the user
    printf("Rows : ");
    int row_count;
    scanf("%d", &row_count);

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 1; row <= row_count; row++)
        {
            //Inner loop to print space
            for (col = 0; col <= row; col++)
            {
                printf(" ");
            }
            //Inner loop to print character
            for (col = 0; col <= row_count - row; col++)
            {
                printf("%c ", (char)(asciiValue + col));
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}


Output:

Character : A
Rows : 5

A B C D E
  A B C D
   A B C
    A B
      A

C++ to Print Downward Triangle Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 1; row <= row_count; row++)
        {
            //Inner loop to print space
            for (col = 0; col <= row; col++)
            {
                cout << " ";
            }
            //Inner loop to print characters
            for (col = 0; col <= row_count - row; col++)
            {
                cout << (char)(asciiValue + col) << " ";
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

  A B C D E
   A B C D
    A B C
     A B
      A

Java Program to Print Right Angled Triangle with Same Character Pattern

Program to Print Right Angled Triangle with Same Character Pattern

In this program we are going to see how to print the right angled triangle with same character pattern.

Example-1

When character=f 
and row value=3

f
f f
f f f
Example-2:

When character=A 

and row value=5

A
A A
A A A
A A A A
A A A A A

Now, let’s see the actual program to print it.

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

Approach:

  • Enter the character and store it in a variable c.
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a new line.

JAVA CODE:

import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
    Scanner scan = new Scanner(System.in);
    //Taking character to be printed as input from the user
    System.out.print("Character : ");
    char c = scan.next().charAt(0);

    //Taking number of rows as input from the user
    System.out.print("Rows : ");
    int row_count = scan.nextInt();

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int) c;

    //Checks whether the character is a letter or not
    if(asciiValue>=65&&asciiValue<=122)
    {
        //Outer loop to iterate rows
        for(row = 0; row<row_count; row++)
        {
            //Inner loop to iterate columns
            for(col = 0; col<row+1; col++)
            {
                System.out.print(c+" ");
            }
            //Prints a newline
            System.out.println();
        }
    }
  }
}


Output:

Character : A
Rows : 5

A
A A
A A A
A A A A
A A A A A

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Character : ");
    char c;
    scanf("%c", &c);

    //Taking number of rows as input from the user
    printf("Rows : ");
    int row_count;
    scanf("%d", &row_count);

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                printf("%c ", c);
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

A
A A
A A A
A A A A
A A A A A

C++ CODE

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << c << " ";
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}


Output:

Character : A
Rows : 5

A
A A
A A A
A A A A
A A A A A

Related Java Star Pattern Programs:

Java Program to Print letters of a string in Inverted Right Angled Triangle Character Pattern

Printing letters of a string in Inverted Right Angled Triangle Pattern

In the previous article, we have discussed Java Program to Print Pyramid with Column wise Same Character Pattern

In this program we are going to see how to print Letters of a string in inverted right angle character pattern.

Example-1

When String value= Example

Example
Exampl
Examp
Exam
Exa
Ex
E
Example-2:

When String value= PatternString

PatternString
PatternStrin
PatternStri
PatternStr
PatternSt
PatternS
Pattern
Patter
Patte
Patt
Pat
Pa
P

Now, let’s see the actual program to print it.

Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.

Approach:

  • Enter the string and store it in an variable str.
  • Take one outer for loop to iterate the rows,
  • Inside the for loop, take one for loop, one to print the string.
  • After each iteration print a newline.

Java Code to Print letters of a string in Inverted Right Angled Triangle Character Pattern

import java.util.Scanner;
class Main
{
public static void main(String[] args)  
{  
    Scanner scan = new Scanner(System.in);

    //Taking string as input from the user
    System.out.print("String : ");
    String str = scan.nextLine();
    scan.close();

    int row,col;
    
    //Length of the string
    int len = str.length();
    //Coverting the String to a character array
    char[] charArray = str.toCharArray();

    //Outer loop to iterate rows
    for(row = len-1; row>=0; row--)
    {
        //Inner loop to iterate columns and print string
        for(col = 0; col<=row; col++)
        {
            System.out.print(charArray[col]);
        }
        //Prints a newline
        System.out.println();
    }
}  
}
Output:

String : BtechGeeks
BtechGeek
BtechGee
BtechGe
BtechG
Btech
Btec
Bte
Bt
B

C Code to Print letters of a string in Inverted Right Angled Triangle Character Pattern

#include <stdio.h>
#include <string.h>

int main()
{
    //Taking string as input from the user
    printf("String : ");
    char str[100];
    gets(str);

    int row, col;

    int len = strlen(str); //Length of the string               

    //Outer loop to iterate rows
    for (row = len - 1; row >= 0; row--)
    { 
        //Inner loop to iterate columns and print string
        for (col = 0; col <= row; col++)
        {
            printf("%c", str[col]);
        }
        //Prints a newline
        printf("\n");
    }
    return 0;
}

Output:

String : BtechGeeks
BtechGeek
BtechGee
BtechGe
BtechG
Btech
Btec
Bte
Bt
B

C++ Code to Print letters of a string in Inverted Right Angled Triangle Character Pattern

#include <iostream>
#include <cstring>
#include <string.h>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking string as input from the user
    cout << "String : ";
    string str;
    cin >> str;

    char charArray[100];
    //Copying the String to a character array
    strcpy(charArray, str.c_str());

    int row, col;

    //Length of the character Array
    int len = strlen(charArray);

    //Outer loop to iterate rows
    for (row = len - 1; row >= 0; row--)
    {
        //Inner loop to iterate columns and print string
        for (col = 0; col <= row; col++)
        {
            cout << charArray[col];
        }
        //Prints a newline
        cout << endl;
    }
    return 0;
}
Output:

String : BtechGeeks
BtechGeek
BtechGee
BtechGe
BtechG
Btech
Btec
Bte
Bt
B

Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.

Related Java Character Pattern Programs:

Java Program to Print Pyramid with Column wise Increasing Character Pattern

Program to Print Pyramid with Column wise Increasing Character Pattern

In the previous article, we have discussed Java Program to Print Hollow Diamond within Rectangle Character Pattern

In this program we are going to see how to print the pyramid column wise increasing character pattern.

Example-1

When row value=5

        A   
      ABA  
    ABCBA 
  ABCDCBA
ABCDEDCBA
Example-2:

When row value=9

                A
              ABA
            ABCBA
          ABCDCBA
        ABCDEDCBA
      ABCDEFEDCBA
    ABCDEFGFEDCBA
  ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA

Now, let’s see the actual program to print it.

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

Approach:

  • Enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Inside the for loop, take three inner for loops, one to print the space and the other for characters.
  • After each iteration print a new line.

Java Code to Print Pyramid with Column wise Increasing Character Pattern

import java.util.Scanner;
class Main
{
public static void main(String[] args)  
{  
    Scanner scan = new Scanner(System.in);

    //Taking number of rows as input from the user
    System.out.print("Rows : ");
    int row_count = scan.nextInt();

    int row, col;
    //Outer for loop to iterate the rows
    for (row = 1; row <= row_count; row++)
    {
        //Loop to print space
        for (col = 1;col <=row_count-row;col++)
        {
            System.out.print(" ");
        }
        //Loop to print char
        for (col = 1; col <= row; col++)
        {
            System.out.print((char)(col+64));
        }
        //Loop to print char
        for ( col = row-1; col >= 1; col--)
        {
            System.out.print((char)(col+64));
        }
        //Prints a newline
        System.out.println();
    }
}  

}


Output

Rows : 9

              A
            ABA
          ABCBA
        ABCDCBA
      ABCDEDCBA
     ABCDEFEDCBA
   ABCDEFGFEDCBA
 ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA

C Code to Print Pyramid with Column wise Increasing Character Pattern

#include <stdio.h>

int main()
{
    //Taking number of rows as input from the user
    printf("Rows : ");
    int row_count;
    scanf("%d", &row_count);

    int row, col;

    // Outer for loop to iterate the rows
    for (row = 1; row <= row_count; row++)
    {
        //Loop to print space
        for (col = 1; col <= row_count - row; col++)
        {
            printf(" ");
        }
        //Loop to print char
        for (col = 1; col <= row; col++)
        {
            printf("%c", (col + 64));
        }
        //Loop to print char
        for (col = row - 1; col >= 1; col--)
        {
            printf("%c", (col + 64));
        }
        //prints a newline
        printf("\n");
    }

    return 0;
}

Output:

Rows : 9

                A
              ABA
            ABCBA
          ABCDCBA
        ABCDEDCBA
      ABCDEFEDCBA
    ABCDEFGFEDCBA
  ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA

C++ Code to Print Pyramid with Column wise Increasing Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;

    // Outer for loop to iterate the rows
    for (row = 1; row <= row_count; row++)
    {
        //Loop to print space
        for (col = 1; col <= row_count - row; col++)
        {
            cout << " ";
        }
        //Loop to print char
        for (col = 1; col <= row; col++)
        {
            cout << (char)(col + 64);
        }
        //Loop to print char
        for (col = row - 1; col >= 1; col--)
        {
            cout << (char)(col + 64);
        }
        // prints a newline
        cout << endl;
    }
    return 0;
}

Output:

Rows : 9

                A
              ABA
            ABCBA
          ABCDCBA
        ABCDEDCBA
      ABCDEFEDCBA
    ABCDEFGFEDCBA
  ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA

Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.

Related Java Character Pattern Programs:

Java Program to Print Downward Arrow Mark Symbol Number Pattern

Print Downward Arrow Mark Symbol Number Pattern

In this article we are going to see how to print the downward arrow mark symbol number pattern.

Exampe-1

When size value= 5

   3  
   3  
1 3 5
 234 
   3
Example-2

When size value= 9

     5    
     5    
     5    
     5    
1   5   9
 2  5  8 
  3 5 7  
   456   
     5

Now, let’s see the actual program to print it.

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

Approach:

  • Enter size of the pattern and store it in an integer variable size.
  • Take one outer for loop to iterate the rows.
  • Take one inner for loops, to iterate the columns.
  • After each iteration print a new line.

JAVA CODE:

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
    int size, r, c;
    //prefer odd number
    //Taking size as input from user
    System.out.print("Size : ");
    Scanner scan = new Scanner(System.in);
    size = scan.nextInt();
    //Taking middle of the pattern in negative
    int mid = -size / 2 + 1;
    //Outer Loop
    for (r = 1; r <= size; r++)
    {
        //Inner loop
        for (c = 1; c <= size; c++)
        {
            if (c == size / 2 + 1 || c == mid || c == size - mid + 1)
                System.out.print(c);
            else
                System.out.print(" ");
        }
        //Prints a newline
        System.out.println();
        //Incrementing the mid value
        mid++;
    }
  }
}
Output:

Size :  9
  
     5    
     5    
     5    
     5    
1   5   9
 2  5  8 
  3 5 7  
   456   
     5

C CODE:

#include <stdio.h>
int main()
{
    int size, r, c;
    //Taking size as input from user
    printf("Size : ");
    scanf("%d", &size);
    //Taking middle of the pattern in negative
    int mid = -size / 2 + 1;
    //Outer Loop
    for (r = 1; r <= size; r++)
    {
        //Inner loop
        for (c = 1; c <= size; c++)
        {
            if (c == size / 2 + 1 || c == mid || c == size - mid + 1)
                printf("%d",c);
            else
                printf(" ");
        }
        //Prints a newline
        printf("\n");
        //incrementing the mid value
        mid++;
    }
    return 0;
}
Output:

Size :  9

     5    
     5    
     5    
     5    
1   5   9
 2  5  8 
  3 5 7  
   456   
     5

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int size, r, c;
    //Taking size as input from user
    cout << "Size : ";
    cin >> size;
    //Taking middle of the pattern in negative
    int mid = -size / 2 + 1;
    //Outer Loop
    for (r = 1; r <= size; r++)
    {
        //Inner loop
        for (c = 1; c <= size; c++)
        {
            if (c == size / 2 + 1 || c == mid || c == size - mid + 1)
                cout << c;
            else
                cout << " ";
        }
        //Prints a newline
        cout << endl;
        //Incrementing the mid value
        mid++;
    }
    return 0;
}
Output:

Size :  9
  
     5    
     5    
     5    
     5    
1   5   9
 2  5  8 
  3 5 7  
   456   
     5

Java Program to Print Hollow Square with Increasing Number Pattern

Print Hollow Square with Increasing Number Pattern

In the previous article, we have discussed Java Program to Print Hollow Square with Repeated Number Pattern

In this program we are going to see how to print the hollow square with increasing number pattern.

Example-1

When size value=5 
and start number = 1

1 1 1 1 1
2          2
3          3
4          4
5 5 5 5 5
Example-2:

When size value=3 
and start number = 5

5 5 5
6    6
7 7 7

Now, let’s see the actual program to print it.

Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.

Approach:

  • Enter total size and start number store them in integer variables size & num respectively.
  • Take one outer for loop to iterate the rows,
  • Take one inner for loop to iterate the columns.
  • After each iteration print a new line.

Java Code to Print Hollow Square with Increasing Number Pattern

import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
    //Create a new Scanner object
    Scanner scan = new Scanner(System.in);

    //Taking size as input from user
    System.out.print("Size of square : ");
    int size = scan.nextInt();

    //Taking number as input from user
    System.out.print("Number to print from : ");
    int num = scan.nextInt();

    //Row and column are the iterators
    int numberOfRows, numberOfColumns;

    //Outer loop to iterate the rows
    //Iterates from 1 to the size entered by the user
    for (numberOfRows = 1; numberOfRows <= size; numberOfRows++)
    {
        //Inner loop to iterate the columns
        //Iterates from 1 to the size entered by the user
        for (numberOfColumns = 1; numberOfColumns <= size; numberOfColumns++)
        {
            //Prints the num value if condition matches else prints space
            if (numberOfColumns == 1 || numberOfColumns == size || numberOfRows == 1 || numberOfRows == size)
                System.out.print(num+ " ");
            else
                System.out.print("  ");
        }
        //Incrementing numbe after each iteration
        num++;
        //Prints a newline
        System.out.println();
    }
}
}
Output:

Size of square : 5
Number to print from : 1

1 1 1 1 1 
2          2 
3          3 
4          4 
5 5 5 5 5

C Code to Print Hollow Square with Increasing Number Pattern

#include <stdio.h>

int main()
{
    //Taking size as input from user
    printf("Size of square : ");
    int size;
    scanf("%d", &size);

    //Taking number as input from user
    printf("Number to print from : ");
    int num;
    scanf("%d", &num);

    //Row and column are the iterators
    int numberOfRows, numberOfColumns;

    //Outer loop to iterate the rows
    //Iterates from 1 to the size entered by the user
    for (numberOfRows = 1; numberOfRows <= size; numberOfRows++)
    {
        //Inner loop to iterate the columns
        //Iterates from 1 to the size entered by the user
        for (numberOfColumns = 1; numberOfColumns <= size; numberOfColumns++)
        {
            //Prints the num value if condition matches else prints space
            if (numberOfColumns == 1 || numberOfColumns == size || numberOfRows == 1 || numberOfRows == size)
                printf("%d ", num);
            else
                printf("  ");
        }
        //Incrementing numbe after each iteration
        num++;
        //Prints a newline
        printf("\n");
    }
    return 0;
}
Output:

Size of square : 5
Number to print from : 1

1 1 1 1 1 
2          2 
3          3 
4          4 
5 5 5 5 5

C++ Code to Print Hollow Square with Increasing Number Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking size as input from user
    printf("Size of square : ");
    int size;
    cin >> size;

    //Taking number as input from user
    printf("Number to print from : ");
    int num;
    cin >> num;

    //Row and column are the iterators
    int numberOfRows, numberOfColumns;

    //Outer loop to iterate the rows
    //Iterates from 1 to the size entered by the user
    for (numberOfRows = 1; numberOfRows <= size; numberOfRows++)
    {
        //Inner loop to iterate the columns
        //Iterates from 0 to one less than the size entered by the user
        for (numberOfColumns = 1; numberOfColumns <= size; numberOfColumns++)
        {
            //Prints the num value if condition matches else prints space
            if (numberOfColumns == 1 || numberOfColumns == size || numberOfRows == 1 || numberOfRows == size)
                cout << num << " ";
            else
                cout << "  ";
        }
        //Incrementing numbe after each iteration
        num++;
        //Prints a newline
        cout << endl;
    }
    return 0;
}

Output:

Size of square : 5
Number to print from : 1

1 1 1 1 1 
2          2 
3          3 
4          4 
5 5 5 5 5

Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.

Related Java Number Pattern Programs: