In: Computer Science
Use nested for loops statements to generate the following output. (Java)
-----1
---22
--333
4444
Ignore the dashes formatting wouldnt allow for extra spaces behind the numbers
Code:-
public class Main
{
   public static void main(String[] args) {
       int i,j;
       //this loop is for 4
iterations
       for(i=1;i<=4;i++)
       {
       //this loop is for printing spaces
or dashes indicated in the question
       for(j=1;j<=4-i;j++)
       {
       System.out.print(" ");
       }
       //this loop is for printing the
numbers
       for(j=1;j<=i;j++)
       {
       System.out.print(i);
       }
       System.out.println();
       }
   }
}
Output and Screenshot of Code:-
