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 28 | import java.util.Scanner; public class Main { public static void main(String args[]) { String str; int i, j; char[] ch; Scanner sc = new Scanner(System.in); System.out.print("Enter a Word: "); str = sc.nextLine(); ch = str.toCharArray(); int strLength = ch.length; for (i = 0; i < strLength; i++) { for (j = 1; j <= strLength; j++) { System.out.print(str.charAt(strLength - j) + " "); } System.out.println(); } } } |
Output:
Enter a Word: SIMPLE
E L P M I S
E L P M I S
E L P M I S
E L P M I S
E L P M I S
E L P M I S