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

Showing posts with label Java Number Pattern Programs. Show all posts
Showing posts with label Java Number Pattern Programs. Show all posts

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:

Tuesday, 8 August 2017

Number Pattern Programs In Java

Java Number Pattern Programs

Number Pattern Programs

This article is all about of number pattern programs in java. This number pattern program is also a very important from the interview point of view.

Here we will see many java number pattern programs examples.

So let's start with it.

Number Pattern 1 :

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Solution :

class Demo1
{
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();
}
}
}

Number Pattern 2 :

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Solution :


class Demo2
{
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();
}
}

}


Number Pattern 3 :

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1

Solution :


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


Number Pattern 4 :

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Solution :


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

Here we are performing number pattern programs in java using for loop. In other words, here we are using nested loop i.e loop inside another loop.



Number Pattern 5 :

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

Solution :


class Demo5
{
public static void main(String args[])
{
for(int i = 1; i <= 5; 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();
}
}
}

Number Pattern 6 :

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

Solution :


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

here another number pattern program in java which will help you in a java programming interviews.

Learn more : Top 10 Frequently asked java number pattern programs - Part 2.

Number Pattern 7 :

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Solution :


class Demo7
{
public static void main(String args[])
{
//upper half of the pattern
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <=i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}

//lower half of the pattern
for(int i = 5-1; i >= 1; i--)
{
for(int j = 1; j <=i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}

Number Pattern 8 :

8 7 6 5 4 3 2 1
8 7 6 5 4 3 2
8 7 6 5 4 3
8 7 6 5 4  
8 7 6 5
8 7
8

Solution :


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

Number Pattern 9 :

1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8

Solution :


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

Number Pattern 10 :

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1
8 7 6 5 4 3 2 1

Solution :


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

}
}

Read More:

Star Pattern Programs in Java.
Alphabet Pattern Programs in Java.
Java Program to Check Leap Year or Not.
Java Program for Linear Search.
Java Program for Binary Search.
Java Program to Find Area of Square.


Here above all the java program to print of number are quite useful and all the above number pattern programs increase your logical capability.


Share:

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Link

Translate