Description: This program prints the following pattern:
0
10
101
0101
10
101
0101
01010
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 23 |
//Primary Input : Generates a single digit number (n) representing the number of lines /* Primary Output: The following pattern is generated for n lines 0 10 101 0101 01010 */ class Pattern3 { public static void main(String args[]) { int n, count = 0; 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++, count++) System.out.print(count % 2); System.out.println(); } } // end of main } |