Wednesday, July 1, 2015

Star Printing And X in Ractangle Pattern Printing In java


public class StarRectangle {

public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
System.out.println("enter size for rectangle");
int n=scn.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)

if(i==1|| i==n|| j==1|| j==n)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
System.out.println();
}

System.out.println("prin X in star");

for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)

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


}

}

0 comments:

Post a Comment