Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete Java program using nested-for loops to produce the following pa

ID: 3929856 • Letter: W

Question

Write a complete Java program using nested-for loops to produce the following pattern: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 Write a Java program that will ask the user to provide an integer, say n, and use nested-for loops to print a hollow square of size n with asterisks. Use a do-while loop to verify that n is in the range of 1 and 20. For instance, When n = 1, print * When n = 2, print ** ** When n = 10, print ********** * * * * * * * * * * * * * * * * ********** Required testing: enter an integer (1 - 20): 0 enter an integer (1 - 20): -1 enter an integer (1 - 20): 10 enter an integer (1 - 20): 21

Explanation / Answer

public class JavaPyramid5 {

public static void main(String[] args) {

for(int i=5; i>0 ;i--){

for(int j=0; j < i; j++){
System.out.print(j+1);
}

System.out.println("");
}

}
}

Output of the example would be
12345
1234
123
12
1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote