Description: This program prints the following pattern:
1
22
333
4444
22
333
4444
Primary Inputs: Generates a single digit random number
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 22 333 4444 */ class Pattern1 { 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++) { for (int j = 1; j <= i; j++) System.out.print(i); System.out.println(); } } // end of main } |