Explanation :
If n=4 then output will be
1111
1 1
1 1
1111.
Code:
import java.util.Scanner;public class Pattern3
{
public static void main( String args[])
{
System.out.print("Enter the number of rows:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,j;
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
if(j==n || j==1 || i==1 || i==n)
System.out.printf("1");
else
System.out.printf(" ");
}
System.out.printf("\n");
}
sc.close();
}
}
No comments:
Post a Comment