Write java code to display the following:
4 3 2 1
3 2 1
2 1
1
Home
/
Computer Science
/
Write java code to display the following: 4 3 2 1 3 2 1 2 1
Write java code to display the following:
4 3 2 1
3 2 1
2 1
1
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
Public class Pattern{
public static void main(String[] args)
{
for(int i=1;i<=4;i++) //i does the work of printing 4 rows
{
for(int j=1;j<i;j++) //j prints required spaces before numbers in each row
{
System.out.print(" ");
}
for(int k=5-i;k>0;k--) //k prints the numbers in descending order in each row
{
System.out.print(k+" ");
}
System.out.println();
}
}
}