Skip to main content

Program to Print Number Pattern


     Program to Print Number Pattern


      1.    Output 
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Source code:
class NumberPattern
{
 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();
 }
 }
}
     
   

      2.Output
1
10
101
1010
10101
Source Code
class NumberPattern
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
if(j%2 == 0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}            
System.out.println();
}
}
}
    


      3.Output
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
Source Code:
class NumberPattern
{
public static void main(String[] args)
 {
 for (int i = 1; i <= 6; i++)
 {
 for (int j = i; j >= 1; j--)
 {
 System.out.print(j+" ");
 }
System.out.println();
 }
 }
}



4.Output
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
Source Code:
class NumberPattern
{
public static void main(String[] args)
{
 for (int i = 1; i <= 6; i++)
 {
 for (int j = 1; j <= i; j++)
  {
  System.out.print(j+" ");
  }
  for (int j = i-1; j >= 1; j--)
  {
  System.out.print(j+" ");
 }
 System.out.println();
 }
}
}



5.Output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6 
Source Code
class NumberPattern
{
public static void main(String[] args)
{
for (int i = 1; i <= 6; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(i+" ");
}
  System.out.println();
}
}

Comments