In this tutorial, we will go through the string pattern program in java. Before that, you may go through the following topic in java.
String Pattern:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public class Main { public static void main(String args[]) { String str = "Simple2Code"; int n = 6; int x = 0; int i, j, k; for (i = 0; i < n; i++) { for (j = 0; j < i; j++) System.out.print(" "); for (k = 0; k < n - i; k++) { System.out.print(str.charAt(x++) + " "); if (x == str.length()) x = 0; } System.out.println(); } } } |
Output:
1 2 3 4 5 6 | S i m p l e 2 C o d e S i m p l e 2 C o d |