Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Tuesday, 10 October 2017

Top 10 Frequently Asked Java Number Pattern Programs - Part 2

Number Pattern Programs in Java

Java Number Pattern Programs

We saw some most important number pattern programs in part - 1 which is mostly asked in core java written interviews and here we will see top 10 frequently asked java number pattern programs which also asked in java interviews. This is number pattern programs in java part - 2

Let's see java number pattern programs examples one-by-one.

Java Number Pattern 1 :

1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
1 0 1 0 1 0
1 0 1 0 1 0 1

Solution :

class Pattern1
{
public static void main(String args[])
{
for(int i = 1; i <= 7; i++)
{
for(int j = 1; j <= i; j++)
{
if(j%2 == 0)

{
System.out.println(0);

}
else
{
System.out.println(1);
}
}
System.out.println();
}
}
}

Java Number Pattern 2 :

1
01
101
0101
10101
010101

Solutions :

class Pattern2
{
public static void main(String args[])
{
for(int i = 1; i <= 6; i++)
{
int n;
if(i%2 == 0)
{
n = 0;
for(int j = 1; j <= i; j++)
{
System.out.print(n);
n = (n == 0)? 1 : 0;
}
}
else
{
n = 1;
for(int j = 1; j <= i; j++)
{
System.out.print(n);
n = (n == 0)? 1 : 0;
}
}
System.out.println();
}
}
}

Java Number Pattern 3 :


00000
01000
00200
00030
00004

Solution :

class Pattern3
{
public static void main(String args[])
{
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 5; j++)
{
if(i == j)
{
System.out.print(i);
}
else
{
System.out.print(0);
}
}
System.out.println();
}
}
}

Java Number Pattern 4 :

101010
010101
101010
010101
101010
010101


Solution :

class Pattern4
{
public static void main(String args[])
{
for(int i = 1; i <= 6; i++)
{
int n;
if(i%2 == 0)
{
n = 0;
for(int j = 1; j <= 6; j++)
{
System.out.print(n);
n = (n == 0)? 1 : 0;
}
}
else
{
n = 1;
for(int j = 1; j <= 6; j++)
{
System.out.print(n);
n = (n == 0)? 1 : 0;
}
}
System.out.println();
}
}
}

Java Number Pattern 5 :

111111
111122
111333
114444
155555
666666

Solution :

class Pattern5
{
public static void main(String args[])
{
for(int i = 1; i <= 6; i++)
{
for(int j = 1; j <= 6-i; j++)
{
System.out.print(1);
}
for(int j = 1; j <= i; j++)
{
System.out.print(i);
}
System.out.println();
}
}
}

Java Number Pattern 6 :

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Solutions :

class Pattern6
{
public static void main(String args[])
{
int number = 1;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
System.out.print(number+ " ");
++number;
}
System.out.println();
}
}
}

Java Number Pattern 7 :

1 2 3
4 5 6
7 8 9

Solutions :

class Pattern7
{
public static void main(String args[])
{
for(int i = 1; i <= 9; i++)
{
for(int j = 1; j <= 3; j++)
{
System.out.print(""+i);
i++;
}
i--;
System.out.println();
}
}
}

Java Number Pattern 8 :

5432112345
4321  1234
321   123
21    12
1     1

Solutions :

class Pattern8
{
public static void main(String args[])
{
for(int i = 1; i <= 5; i++)
{
for(int j = 6-i; j >= 1; j--)
{
System.out.print(j);

}
if(i>1)
{
System.out.print(" ");
}
for(int k = 1; k <= 6-i; k++)
{
System.out.print(k);
}
System.out.println();
}
}
}

Java Number Pattern 9 :

12345
  2345
    345
      45
        5

Solutions :

class Pattern9
{
public static void main(String args[])
{
for(int i = 1; i <= 5; i++)
{
for(int j = 5-i; j < 4; j++)
{
System.out.print(" ");
}
for(int k = i; k <= 5; k++)
{
System.out.print(k);
}
System.out.println();
}
}
}

Java Number Pattern 10 :

1 2 3 4
5 6 7
8 9
10

Solutions :

class Pattern10
{
public static void main(String args[])
{
int temp = 1;
for(int i = 4; i >= 1; i--)
{
for(int j = 1; j <= i; j++)
{
System.out.print(temp++ + " ");

}
System.out.println();
}
}
}

You can check some important start pattern programs in java.

In this article, we performed most important number pattern programs in java by the help of for loop or nested loop.


Share:

8 comments:

  1. Replies
    1. int n=3,t=3;
      for(int i=n;i>=1;i-- )
      {
      for(int j=i;j<=t;j++)
      {
      cout<<j;

      }

      cout<<"\n";

      }

      Delete
    2. for (int i=n;i>=1;i--){
      for(int j=i;j<=n;j++){
      System.out.print(j + " ");
      }
      System.out.println();
      }

      Delete
  2. int main()
    {
    int i,j,k,n,p,p1;
    printf("enter value\n");
    scanf("%d",&n);
    p1=n+1;
    for(i=1;i<=n;i++)
    {p=p1-i;
    for(j=1;j<=i;j++)
    {
    printf("%d",p++);
    }
    printf("\n");
    }

    return 0;
    }

    ReplyDelete
  3. Replies
    1. #include

      /*

      1
      123
      1
      1234

      */

      main()
      {
      int num=3;
      for(int i=1;i<=4;i++)
      {
      if(i%2!=0)
      {
      printf("1");
      printf("\n");
      continue;
      }
      for(int j=1;j<=num;j++)
      {
      printf("%d",j);
      }
      num++;
      printf("\n");
      }
      }

      Delete
  4. Replies
    1. #include

      /*

      1
      123
      1
      1234

      */

      main()
      {
      int p=3,num=1;
      for(int i=1;i<=4;i++)
      {
      if(i%2!=0)
      {
      printf("1");
      printf("\n");
      continue;
      }
      for(int j=1;j<i+1;j++)
      {
      printf("%d",j);
      }
      printf("\n");
      }
      }

      Delete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate