Solved: Write a complete java program that printout the following pattern using nested loops:

Write a complete java program that printout the following pattern using nested loops:

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1

I have this:

public class trying {
/** Main method */
public static void main(String[] args) {

//count down from 5
for (int i = 7 ; i >= 1; i–) {
System.out.println();

//count down from 6
for (int j = 7- i; j >= 1; j–) {

System.out.printf(“%4d”, j);
}
}

}}

but it prints this:

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1

Expert Answer

 

public class pattern {

public static void main(String args[]){

int n=6,j,k,i;

//outer loop to print six lines
for(i=1;i<=n;i++){

// this loop to print spaces
for(j=(n-i);j>=1;j–)
System.out.print(” “);

//this loop to print numbers
for(j=i;j>=1;j–)
System.out.print(j+” “);

System.out.println();
}

}

}

Still stressed from student homework?
Get quality assistance from academic writers!