Program to Print Digit 8 Character Pattern
In the previous article, we have discussed Java Program to Print Plus Character Pattern
In this article we are going to see how to print the number ‘8’ character pattern.
Example: Size : 8 AAAA B B C C D D E E FFFF G G H H I I J J KKKK
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 size and store it in an integer variable
size
. - Take first for loop to print all rows.
- Take second/inner for loop to print column values.
- Then go on printing the star symbols according to the iteration and if else condition.
Java Code to Print Digit 8 Character Pattern
import java.util.Scanner; class Main { public static void main(String[] args) { //starting ascii value taken 64 int ascii=64; Scanner scan = new Scanner(System.in); System.out.print("Size : "); //Taking size as input from user int r, c, size=scan.nextInt(); int k = size*2-1; for(r = 1; r<=k; r++) { //Outer loop if(r==1||r==size||r==k) for(c = 1;c<=size;c++) { //Inner Loop 1 if(c==1||c==size) System.out.print(" "); else System.out.print((char)(r+ascii)); } else for(c = 1;c<=size;c++) { //Inner loop 2 if(c==1||c==size) System.out.print((char)(r+ascii)); else System.out.print(" "); } //Prints a new line System.out.println(); } } }
Output: Size : 8 AAAA B B C C D D E E FFFF G G H H I I J J KKKK
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: