Write a complete Java program using nestedfor loops to produ

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

Solution

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

 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site