Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Java Number Diagonal using For Loop

  1. /*
  2.     Write a program to output the following pattern using for loop.
  3.   1
  4.     2
  5.      3
  6.        4
  7.          5
  8. */
  9.  
  10. public class Diagonal {
  11.  
  12.     public static void main (String[]args) {
  13.  
  14.           for (int x=1; x<=5; x++){
  15.                for (int y=1; y<=x; y++){
  16.                  System.out.print("");
  17.                }
  18.                System.out.println(x);
  19.           }
  20.  
  21.     }
  22.  
  23. }
Your rating: None Average: 3 (2 votes)
Share this

Post new comment

3 + 11 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.