Wednesday, January 22, 2014

Display numbers pyramid pattern java

Write a program to display the following output

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


import java.util.Scanner;
public class ForLoop1
{
    public static void main(String[] args)
     {
       System.out.println("Enter the limit:-");
        Scanner sc=new Scanner(System.in);
    int limit=sc.nextInt();
   for(int i=1;i<=limit;i++)
   {
    for(int j=1;j<=i;j++)
     {
    System.out.print( i +"  ");
     }
       System.out.println();
  }
    }
}


Output:
Enter the limit:-
5

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






No comments:

Post a Comment