Wednesday, January 22, 2014

Display square numbers pyramid pattern java


Write a program to print the following output with the given character

ENTER THE CHARACTER TO BE DISPLAYED:-
8

ENTER THE LIMIT:-
4

8 8 8 8
8       8
8       8
8 8 8 8



import java.util.Scanner;
public class GenerateNumber1
{
public static void main(String[] args)
{
int i,j,x=0;
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE CHARACTER TO BE DISPLAYED:-");
int  c=sc.nextInt();
System.out.println( "ENTER THE LIMIT:-");
int n=sc.nextInt();

for(i=1;i<=n;i++)
 {
  for(j=1;j<=n;j++)
  {   
    if(i==1||j==1||j==n||i==n)  
       System.out.print(c+" ");
    else
      System.out.print("  ");
  }
  System.out.println();
 }
}
}





No comments:

Post a Comment