Printing Greater Than Symbol Character Pattern
In the previous article, we have discussed Java Program to Print Less Than Symbol Character Pattern
In this article we are going to see how to print the greater than symbol character pattern.
Example-1 When size value=7 A B C D C B A
Example-2 When size value=5 A B C B A
Now, let’s see the actual program to print it.
Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners tutorial.
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; class Main { public static void main(String[] args) { // variable 'size' refers to number of throws // variable 'r' and 'c' are used to iterate the for loop for rows and columns int size, r, c; // Scanner class object created Scanner scan = new Scanner(System.in); //Taking size as input from user System.out.print("Size : "); size = scan.nextInt(); // Mainly this 'd' value represents the column position int d = 1; // ASCII value taken 64 int asciiAlpha = 64; //Outer Loop //This for loop will iterate all the rows for (r = 1; r <= size; r++) { //Inner loop //This for loop is used to iterate all the columns // During iteration it will print the column values for each row for (c = 1; c <= size; c++) { // if 'c' value matches with 'd' value // then in the 'd' position respective character will be printed if (c == d) // Printing character System.out.print((char)(c + asciiAlpha)); else // Printing space System.out.print(" "); } //Prints a newline System.out.println(); //Adjusting the d value if (r <= size / 2) d++; else d--; } } }
Output: Size: 7 A B C D C B A
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: