Description: This program prints the following pattern:
1
222
33333
4444444
222
33333
4444444
Primary Inputs: Generates a single digit random number as the number of lines
Primary Output: The pattern specified above
Platform Used: JDK 1.6 with JCreator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
//Primary Input : Generates a single digit number (n) representing the number of lines /* Primary Output: The following pattern is generated for n lines 1 222 33333 4444444 */ class Pattern2 { public static void main(String args[]) { int n; n = (int) (Math.random() * 10); System.out.println("The number of lines are: " + n); for (int i = 1; i <= n; i++) { int count = 2 * i - 1; for (int j = 1; j <= count; j++) System.out.print(i); System.out.println(); } } // end of main } |