Different Patterns in Java.
Pattern 1:
class Pattern1
{
public static void main(String args[])
{
System.out.println();
for(int i=0; i<5; i++)
{
for(int j=0; j<i+1; j++)
{
System.out.print(" * ");
}
System.out.println();
}
}
}
{
public static void main(String args[])
{
System.out.println();
for(int i=0; i<5; i++)
{
for(int j=0; j<i+1; j++)
{
System.out.print(" * ");
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 2:
class Pattern2
{
public static void main(String args[])
{ System.out.println();
for(int i=5; i>0; i--)
{
for(int j=0; j<i+1; j++)
{
System.out.print(" * ");
}
System.out.println();
}
}
}
{
public static void main(String args[])
{ System.out.println();
for(int i=5; i>0; i--)
{
for(int j=0; j<i+1; j++)
{
System.out.print(" * ");
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 3:
class Pattern3
{
public static void main(String args[])
{
for(int i=1; i<=7; i++)
{
for(int j=1; j<7-i+1; j++)
{
System.out.print(" "); // 3 blank spaces
}
for(int k=1; k<=i; k++)
{
// 1 blank space, 1 char, 1 blank space
System.out.print(" * ");
for(int l=1; l<k; l+=k)
{
System.out.print(" * ");
}
}
System.out.println();
}
}
}
{
public static void main(String args[])
{
for(int i=1; i<=7; i++)
{
for(int j=1; j<7-i+1; j++)
{
System.out.print(" "); // 3 blank spaces
}
for(int k=1; k<=i; k++)
{
// 1 blank space, 1 char, 1 blank space
System.out.print(" * ");
for(int l=1; l<k; l+=k)
{
System.out.print(" * ");
}
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 4:
class Pattern4
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=i; j>1; j--)
{
System.out.print(" ");
}
for(int k=1; k<=7-i+1; k++)
{
System.out.print(" * ");
for(int l=1; l<k; l+=k)
{
System.out.print(" * ");
}
}
System.out.println();
}
}
}
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=i; j>1; j--)
{
System.out.print(" ");
}
for(int k=1; k<=7-i+1; k++)
{
System.out.print(" * ");
for(int l=1; l<k; l+=k)
{
System.out.print(" * ");
}
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 5:
class Pattern5
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=1; j<7-i+1; j++)
{
System.out.print(" "); // 3 blank spaces
}
for(int k=1; k<=i; k++)
{
// 1 blank space, 1 char, 1 blank space
System.out.print(" * ");
for(int l=1; l<k; l+=k)
{
System.out.print(" * ");
}
}
System.out.println();
}
//===================================
for(int i=2; i<=7; i++)
{
for(int j=i; j>1; j--)
{
System.out.print(" ");
}
for(int k=1; k<=7-i+1; k++)
{
System.out.print(" * ");
for(int l=1; l<k; l+=k)
{
System.out.print(" * ");
}
}
System.out.println();
}
}
}
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=1; j<7-i+1; j++)
{
System.out.print(" "); // 3 blank spaces
}
for(int k=1; k<=i; k++)
{
// 1 blank space, 1 char, 1 blank space
System.out.print(" * ");
for(int l=1; l<k; l+=k)
{
System.out.print(" * ");
}
}
System.out.println();
}
//===================================
for(int i=2; i<=7; i++)
{
for(int j=i; j>1; j--)
{
System.out.print(" ");
}
for(int k=1; k<=7-i+1; k++)
{
System.out.print(" * ");
for(int l=1; l<k; l+=k)
{
System.out.print(" * ");
}
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 6:
class Pattern6
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=1; j<7-i+1; j++)
{
System.out.print(" * ");
}
for(int k=1; k<=i; k++)
{
System.out.print(" ");
for(int l=1; l<k; l+=k)
{
System.out.print(" ");
}
}
System.out.println();
}
//===================================
for(int i=2; i<=7; i++)
{
for(int j=i; j>1; j--)
{
System.out.print(" * ");
}
for(int k=1; k<=7-i+1; k++)
{
System.out.print(" ");
for(int l=1; l<k; l+=k)
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=1; j<7-i+1; j++)
{
System.out.print(" * ");
}
for(int k=1; k<=i; k++)
{
System.out.print(" ");
for(int l=1; l<k; l+=k)
{
System.out.print(" ");
}
}
System.out.println();
}
//===================================
for(int i=2; i<=7; i++)
{
for(int j=i; j>1; j--)
{
System.out.print(" * ");
}
for(int k=1; k<=7-i+1; k++)
{
System.out.print(" ");
for(int l=1; l<k; l+=k)
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 7:
class Pattern7
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=1; j<=7-i+1; j++)
{
System.out.print(" * ");
if(j==(7 - i+1))
{
for(int k=1; k<=i; k++)
{
System.out.print(" ");
}
for(int l=1; l<i; l++)
{
System.out.print(" ");
}
for(int m=1; m<=7-i+1; m++)
{
System.out.print(" * ");
}
}
}
System.out.println();
}
}
}
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=1; j<=7-i+1; j++)
{
System.out.print(" * ");
if(j==(7 - i+1))
{
for(int k=1; k<=i; k++)
{
System.out.print(" ");
}
for(int l=1; l<i; l++)
{
System.out.print(" ");
}
for(int m=1; m<=7-i+1; m++)
{
System.out.print(" * ");
}
}
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 8:
class Pattern8
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=7-i; j<7; j++)
{
System.out.print(" * ");
if(j==(6))
{
for(int k=i; k<=j+1; k++)
{
System.out.print(" ");
}
for(int l=1; l<7-i+1; l++)
{
System.out.print(" ");
}
for(int m=7-i; m<7; m++)
{
System.out.print(" * ");
}
}
}
System.out.println();
}
}
}
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=7-i; j<7; j++)
{
System.out.print(" * ");
if(j==(6))
{
for(int k=i; k<=j+1; k++)
{
System.out.print(" ");
}
for(int l=1; l<7-i+1; l++)
{
System.out.print(" ");
}
for(int m=7-i; m<7; m++)
{
System.out.print(" * ");
}
}
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 9:
class Pattern9
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=1; j<=7-i+1; j++)
{
System.out.print(" * ");
if(j==(7 - i+1))
{
for(int k=1; k<=i; k++)
{
System.out.print(" ");
}
for(int l=1; l<i; l++)
{
System.out.print(" ");
}
for(int m=1; m<=7-i+1; m++)
{
System.out.print(" * ");
}
}
}
System.out.println();
}
//======================================
for(int i=1; i<=7; i++)
{
for(int j=7-i; j<7; j++)
{
System.out.print(" * ");
if(j==(6))
{
for(int k=i; k<=j+1; k++)
{
System.out.print(" ");
}
for(int l=1; l<7-i+1; l++)
{
System.out.print(" ");
}
for(int m=7-i; m<7; m++)
{
System.out.print(" * ");
}
}
}
System.out.println();
}
}
}
{
public static void main(String args[])
{
System.out.println();
for(int i=1; i<=7; i++)
{
for(int j=1; j<=7-i+1; j++)
{
System.out.print(" * ");
if(j==(7 - i+1))
{
for(int k=1; k<=i; k++)
{
System.out.print(" ");
}
for(int l=1; l<i; l++)
{
System.out.print(" ");
}
for(int m=1; m<=7-i+1; m++)
{
System.out.print(" * ");
}
}
}
System.out.println();
}
//======================================
for(int i=1; i<=7; i++)
{
for(int j=7-i; j<7; j++)
{
System.out.print(" * ");
if(j==(6))
{
for(int k=i; k<=j+1; k++)
{
System.out.print(" ");
}
for(int l=1; l<7-i+1; l++)
{
System.out.print(" ");
}
for(int m=7-i; m<7; m++)
{
System.out.print(" * ");
}
}
}
System.out.println();
}
}
}
Out Put is as following :
Pattern 10:
class Pattern10
{
public static void main(String args[])
{
System.out.println();
for(int i=0; i<=10; i++)
{ try
{
Thread.sleep(500);
System.out.println(" * ");
if(i%2==0)
{
Thread.sleep(500);
System.out.println(" * ");
}
else
{
Thread.sleep(500);
System.out.println(" * ");
}
}
catch(Exception e){}
}
}
}
{
public static void main(String args[])
{
System.out.println();
for(int i=0; i<=10; i++)
{ try
{
Thread.sleep(500);
System.out.println(" * ");
if(i%2==0)
{
Thread.sleep(500);
System.out.println(" * ");
}
else
{
Thread.sleep(500);
System.out.println(" * ");
}
}
catch(Exception e){}
}
}
}
Out Put is as following :
No comments:
Post a Comment