Designing Patterns - Print 'V'.
SOURCE CODE
import java.io.*;
import java.util.*;
public class V
{
public static void main(String args[])
{
Scanner sc=new Scanner (System.in);
System.out.print("Enter a odd number >=5 :");
int n=sc.nextInt();
int a=n/2+1,s=-a,l=n+a-1;
System.out.println("\n");
if(n>=5&& n%2!=0 )
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if((i<=a && (j==1||j==n)) || i>=a && j==s+2 || j==l )
System.out.print("V ");
else
System.out.print(" ");
}
s++;l--;
System.out.println();
}
}
else
System.out.println("Invalid Input.");
}
}
import java.util.*;
public class V
{
public static void main(String args[])
{
Scanner sc=new Scanner (System.in);
System.out.print("Enter a odd number >=5 :");
int n=sc.nextInt();
int a=n/2+1,s=-a,l=n+a-1;
System.out.println("\n");
if(n>=5&& n%2!=0 )
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if((i<=a && (j==1||j==n)) || i>=a && j==s+2 || j==l )
System.out.print("V ");
else
System.out.print(" ");
}
s++;l--;
System.out.println();
}
}
else
System.out.println("Invalid Input.");
}
}
Comments
Post a Comment