Pattern Type One Program in Java
public class Pattern1
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Output:
* ** *** **** *****
public class Pattern2
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(i);
}
System.out.println();
}
}
}
Output:
1 22 333 4444 55555
public class Pattern3
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
Output:
1 12 123 1234 12345
public class Pattern4
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(i % 2);
}
System.out.println();
}
}
}
Output:
1 00 111 0000 11111
public class Pattern5
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j % 2);
}
System.out.println();
}
}
}
Output:
1 10 101 1010 10101
public class Pattern6
{
public static void main(String[] args)
{
int k;
for (int i = 1; i <= 5; i++)
{
k = i;
for (int j = 1; j <= i; j++)
{
System.out.print((k+1) % 2);
k++;
}
System.out.println();
}
}
}
Output:
0 10 010 1010 01010
public class Pattern7
{
public static void main(String[] args)
{
int k = 1;
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(k + " ");
k++;
}
System.out.println();
}
}
}
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
public class Pattern8
{
public static void main(String[] args)
{
int k;
for (int i = 1; i <= 5; i++)
{
k = i;
for (int j = 1; j <= i; j++)
{
System.out.print(k + " ");
k++;
}
System.out.println();
}
}
}
Output:
1 2 3 3 4 5 4 5 6 7 5 6 7 8 9
public class Pattern9
{
public static void main(String[] args)
{
int k;
for (int i = 1; i <= 5; i++)
{
k = i;
for (int j = 1; j <= i; j++)
{
System.out.print(k % 2);
k++;
}
System.out.println();
}
}
}
Output:
1 01 101 0101 10101
public class Pattern10
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
if (i % 2 == 0)
{
System.out.print("#");
}
else
{
System.out.print("*");
}
}
System.out.println();
}
}
}
Output:
* ## *** #### *****
public class Pattern43
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print((char) (i + 64));
}
System.out.println();
}
}
}
Output:
A BB CCC DDDD EEEEE
public class Pattern42
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = i; j >= 1; j--)
{
System.out.print(2 * j - 1);
}
System.out.println();
}
}
}
Output:
1 31 531 7531 97531b. tech. bca icse java java tutorials learn java mca programs