Very Interesting & Logical Pattern (Code in Java)
import java.util.*;
public class Pattern
{
public static void Pattern1(int n, char ch)
{
int i, j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n*4;j++)
{
if(j<=i && j<=n || j>n && j<=n*2+1-i || j>=n*2+i && j<=n*3 || j>=n*4+1-i && j<=n*4)
System.out.print(ch);
else
System.out.print(" ");
}
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=5;
char ch;
System.out.print("Enter Character: ");
ch=sc.next().charAt(0);
System.out.print("Enter N. Lines : ");
n=sc.nextInt();
Pattern1(n,ch);
}
}
public class Pattern
{
public static void Pattern1(int n, char ch)
{
int i, j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n*4;j++)
{
if(j<=i && j<=n || j>n && j<=n*2+1-i || j>=n*2+i && j<=n*3 || j>=n*4+1-i && j<=n*4)
System.out.print(ch);
else
System.out.print(" ");
}
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=5;
char ch;
System.out.print("Enter Character: ");
ch=sc.next().charAt(0);
System.out.print("Enter N. Lines : ");
n=sc.nextInt();
Pattern1(n,ch);
}
}
No comments
Post your comments