Simple Number Pattern-2

Simple Number Pattern-2

1280 720 mrrohit

To print any patterns of numbers or stars (*) in Java Programming, you have to use two loops.

The first is an outer loop and the second is an inner loop.

The outer loop is responsible for rows and the inner loop is responsible for columns.

logic
 
// outer for loop
for(int i=0; i<5; i++)    
         {
//inner for loop will be write here
}
code
 
public class StarAndNumber {
      public static void main(String[] args) {
            // TODO Auto-generated method stub
            int count = 1;
            for(int i=0; i<5; i++)
            {            
                  
                  for(int j=0; j<=i; j++)
                  {
                        System.out.print(count + " ");
                        count++;
                  }
                  System.out.println();
            }
      }
}

 

 

 

 

 

Press Ctrl+C to copy the following code.
"