Best Place for Technologies and Academics Tutorial
java number pattern programs
by
Pattern Example-1
Pattern
----Pattern is----
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){for(int j =1; j <= i; j++){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----112123123412345
Number of rows you want in this pattern?
5
----Pattern is----
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Pattern Example-2
Pattern
----Pattern is----
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
packagecom.w3spoint;importjava.util.Scanner;publicclass Test
{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){for(int j =1; j <= i; j++){System.out.print(i+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(i+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----122333444455555
Number of rows you want in this pattern?
5
----Pattern is----
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){for(int j =1; j <= i; j++){System.out.print(j+" ");}System.out.println();}// lower half of the pattern for(int i = rows-1; i >=1; i--){for(int j =1; j <= i; j++){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
// lower half of the pattern
for (int i = rows-1; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----1121231234123451234123121
Number of rows you want in this pattern?
5
----Pattern is----
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
Pattern Example-4
Pattern
----Pattern is----
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i = rows; i >=1; i--){for(int j =1; j <= i; j++){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----123451234123121
Number of rows you want in this pattern?
5
----Pattern is----
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Pattern Example-5
Pattern
----Pattern is----
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){for(int j = rows; j >= i; j--){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
for (int j = rows; j >= i; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----543215432543545
Number of rows you want in this pattern?
5
----Pattern is----
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
Pattern Example-6
Pattern
----Pattern is----
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i = rows; i >=1; i--){for(int j = rows; j >= i; j--){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = rows; i >= 1; i--)
{
for (int j = rows; j >= i; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----554543543254321
Number of rows you want in this pattern?
5
----Pattern is----
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
Pattern Example-7
Pattern
----Pattern is----
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i = rows; i >=1; i--){for(int j = i; j >=1; j--){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = rows; i >= 1; i--)
{
for (int j = i; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----543214321321211
Number of rows you want in this pattern?
5
----Pattern is----
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i = rows; i >=1; i--){for(int j =1; j <= i; j++){System.out.print(j+" ");}System.out.println();}for(int i =2; i <= rows; i++){for(int j =1; j <= i; j++){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
for (int i = 2; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----12345123412312112123123412345
Number of rows you want in this pattern?
5
----Pattern is----
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
packagecom.w3spoint;importjava.util.Scanner;publicclass Test
{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; 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();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; 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();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----1121123211234321123454321
Number of rows you want in this pattern?
5
----Pattern is----
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
Pattern Example-10
Pattern
----Pattern is----
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){for(int j = i; j >=1; j--){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
for (int j = i; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----121321432154321
Number of rows you want in this pattern?
5
----Pattern is----
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){for(int j =1; j < i; j++){System.out.print(" ");}for(int j = i; j <= rows; j++){System.out.print(j+" ");}System.out.println();}for(int i = rows-1; i >=1; i--){for(int j =1; j < i; j++){System.out.print(" ");}for(int j = i; j <= rows; j++){System.out.print(j+" ");}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
for (int i = rows-1; i >= 1; i--)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----12345234534545545345234512345
Number of rows you want in this pattern?
5
----Pattern is----
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
Pattern Example-13
Pattern
----Pattern is----
1
10
101
1010
10101
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){for(int j =1; j <= i; j++){if(j%2 ==0){System.out.print(0);}else{System.out.print(1);}}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
if(j%2 == 0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----110101101010101
Number of rows you want in this pattern?
5
----Pattern is----
1
10
101
1010
10101
Pattern Example-14
Pattern
----Pattern is----
10101
01010
10101
01010
10101
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){int num;if(i%2 ==0){
num =0;for(int j =1; j <= rows; j++){System.out.print(num);
num =(num ==0)?1:0;}}else{
num =1;for(int j =1; j <= rows; j++){System.out.print(num);
num =(num ==0)?1:0;}}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
int num;
if(i%2 == 0)
{
num = 0;
for (int j = 1; j <= rows; j++)
{
System.out.print(num);
num = (num == 0)? 1 : 0;
}
}
else
{
num = 1;
for (int j = 1; j <= rows; j++)
{
System.out.print(num);
num = (num == 0)? 1 : 0;
}
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----10101
01010
10101
01010
10101
Number of rows you want in this pattern?
5
----Pattern is----
10101
01010
10101
01010
10101
Pattern Example-15
Pattern
----Pattern is----
11111
11122
11333
14444
55555
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){for(int j =1; j <= rows-i; j++){System.out.print(1);}for(int j =1; j <= i; j++){System.out.print(i);}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows-i; j++)
{
System.out.print(1);
}
for (int j = 1; j <= i; j++)
{
System.out.print(i);
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----1111111122113331444455555
Number of rows you want in this pattern?
5
----Pattern is----
11111
11122
11333
14444
55555
Pattern Example-16
Pattern
----Pattern is----
00000
01000
00200
00030
00004
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =0; i < rows; i++){for(int j =0; j < rows; j++){if(i == j){System.out.print(i);}else{System.out.print(0);}}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < rows; j++)
{
if(i == j)
{
System.out.print(i);
}
else
{
System.out.print(0);
}
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----
00000
01000
00200
00030
00004
Number of rows you want in this pattern?
5
----Pattern is----
00000
01000
00200
00030
00004
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){int num = i;for(int j =1; j <= i; j++){System.out.print(num+" ");
num = num+rows-j;}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
int num = i;
for (int j = 1; j <= i; j++)
{
System.out.print(num+" ");
num = num+rows-j;
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----126371048111359121415
Number of rows you want in this pattern?
5
----Pattern is----
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
packagecom.w3spoint;importjava.util.Scanner;publicclass Test{publicstaticvoid main(String[] args){
Scanner scanner =new Scanner(System.in);System.out.println("Number of rows you want in this pattern?");int rows = scanner.nextInt();System.out.println("----Pattern is----");for(int i =1; i <= rows; i++){int num = i;for(int j =1; j <= i; j++){System.out.print(num+" ");
num = num+rows-j;}System.out.println();}
scanner.close();}}
package com.w3spoint;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of rows you want in this pattern?");
int rows = scanner.nextInt();
System.out.println("----Pattern is----");
for (int i = 1; i <= rows; i++)
{
int num = i;
for (int j = 1; j <= i; j++)
{
System.out.print(num+" ");
num = num+rows-j;
}
System.out.println();
}
scanner.close();
}
}
Output
Number of rows you want in this pattern?5----Pattern is----126371048111359121415
Number of rows you want in this pattern?
5
----Pattern is----
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15