Q:

(Display four patterns using loops) Use nested loops that display the following patterns in four separate programs:

0

(Display four patterns using loops) Use nested loops that display the following patterns in four separate programs:

Pattern A       Pattern B         Pattern C        Pattern D
1                   1 2 3 4 5 6                     1        1 2 3 4 5 6
1 2                1 2 3 4 5                     2 1           1 2 3 4 5
1 2 3             1 2 3 4                     3 2 1              1 2 3 4
1 2 3 4          1 2 3                      4 32 1                 1 2 3
1 2 3 4 5       1 2                     5 4 3 2 1                    1 2
1 2 3 4 5 6    1                     6 5 4 3 2 1                       1

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*
(Display four patterns using loops) Use nested loops that display the following
patterns in four separate programs:
*/
public class Exercise_05_18_C {
	public static void main(String[] args) {
		// Display pattern C
		int numberOfLines = 6;
		System.out.println("Pattern C");
		for (int rows = 1; rows <= numberOfLines; rows++) {
			for (int s = numberOfLines - rows; s >= 1; s--) {
				System.out.print("  ");
			}
			for (int col = rows; col >= 1; col--) {
				System.out.print(col + " ");
			}
			System.out.println();
		}
	}
}

Exercise_05_18_D.java

/*
(Display four patterns using loops) Use nested loops that display the following
patterns in four separate programs:
*/
public class Exercise_05_18_D {
	public static void main(String[] args) {
		// Display pattern D
		System.out.println("Pattern D");
		for (int rows = 0; rows < 6; rows++) {				// Print rows
			for (int ws = 0; ws < rows; ws++) {				// Print white space
				System.out.print("  ");
			}
			for (int col = 0; col < 6 - rows; col++) {	// Print numbers
				System.out.print((col + 1) + " ");
			}
			System.out.println();								// Print newline
		}
	}
}

Exercise_05_18_B.java

/*
(Display four patterns using loops) Use nested loops that display the following
patterns in four separate programs:
*/
public class Exercise_05_18_B {
	public static void main(String[] args) {
		// Display pattern B
		System.out.println("Pattern B");
		for (int r = 6; r >= 1; r--) {
			for (int c = 1; c <= r; c++) {
				System.out.print(c + " ");
			}
			System.out.println();
		}
	}
}

Exercise_05_18_A.java

/*
(Display four patterns using loops) Use nested loops that display the following
patterns in four separate programs:
*/
public class Exercise_05_18_A {
	public static void main(String[] args) {
		// Pattern A
		System.out.println("Pattern A");
		for (int rows = 1; rows <= 6; rows++) {
			for (int cols = 1; cols <= rows ; cols++) {
				System.out.print(cols + " ");
			}
			System.out.println();
		}
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now