Java Patterns - Level 1

25+ Java Pattern Questions With Solutions

Java Patterns - Level 1

Pattern Programs in Java Based on:

  • Numeric Patterns

  • Character Patterns

  • Star Patterns in Java

  • Mixed patterns

Pattern Programs - Level 1

Pattern Program 1::

Enter the number: 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n= sc.nextInt();
        for (int i =1;i<=n;i++){
            for (int j=1;j<=n;j++){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 2::

Enter the number: 5
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n= sc.nextInt();
        for (int i =1;i<=n;i++){
            for (int j=1;j<=n;j++){
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 3::

Enter the number: 5
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n= sc.nextInt();
        for (int i =1;i<=n;i++){
            for (int j=n;j>=1;j--){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 4::

Enter the number: 5
5 5 5 5 5
4 4 4 4 4
3 3 3 3 3
2 2 2 2 2
1 1 1 1 1
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n= sc.nextInt();
        for (int i =n;i>=1;i--){
            for (int j=n;j>=1;j--){
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 5::

AAAAA
BBBBB
CCCCC
DDDDD
EEEEE
import java.io.*;
public class Patterns {
    public static void main(String[] args) {
        for (int i=65;i<=69;i++){
            for (int j=65;j<=69;j++){
                System.out.print((char)i);
            }
            System.out.println();
        }
    }
}

Pattern Program 6::

ABCDE
ABCDE
ABCDE
ABCDE
ABCDE
import java.io.*;
public class Patterns {
    public static void main(String[] args) {
        for (int i=65;i<=69;i++){
            for (int j=65;j<=69;j++){
                System.out.print((char)j);
            }
            System.out.println();
        }
    }
}

Pattern Program 7::

EEEEE
DDDDD
CCCCC
BBBBB
AAAAA
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (int i=69;i>=65;i--){
            for (int j=69;j>=65;j--){
                System.out.print((char)i);
            }
            System.out.println();
        }
    }
}

Pattern Program 8::

EDCBA
EDCBA
EDCBA
EDCBA
EDCBA
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (int i=69;i>=65;i--){
            for (int j=69;j>=65;j--){
                System.out.print((char)j);
            }
            System.out.println();
        }
    }
}

Pattern Program 9::

ZYXWV
ZYXWV
ZYXWV
ZYXWV
ZYXWV
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (int i=90;i>=86;i--){
            for (int j=90;j>=86;j--){
                System.out.print((char)j);
            }
            System.out.println();
        }
    }
}

Pattern Program 10::

Enter the number: 5
*
* *
* * *
* * * *
* * * * *
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n=sc.nextInt();
        for (int i=1;i<=5;i++){
            for (int j=1;j<=i;j++){
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}

Pattern Program 11::

Enter the number: 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n=sc.nextInt();
        for (int i=1;i<=5;i++){
            for (int j=1;j<=i;j++){
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 12::

Enter the number: 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n=sc.nextInt();
        for (int i=1;i<=5;i++){
            for (int j=1;j<=i;j++){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 13::

Enter the number: 5
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n=sc.nextInt();
        for (int i=n;i>=1;i--){
            for (int j=n;j>=i;j--){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 14::

Enter the number: 5
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n=sc.nextInt();
        for (int i=n;i>=1;i--){
            for (int j=n;j>=i;j--){
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 15::

A
A B
A B C
A B C D
A B C D E
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {

        for (char i='A';i<='E';i++){
            for (char j='A';j<=i;j++){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 16::

E
D D
C C C
B B B B
A A A A A
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (char i='E';i>='A';i--){
            for (char j='E';j>=i;j--){
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 17::

E
E D
E D C
E D C B
E D C B A
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (char i='E';i>='A';i--){
            for (char j='E';j>=i;j--){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 18::

E D C B A
E D C B
E D C
E D
E
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (char i='A';i<='E';i++){
            for (char j='E';j>=i;j--){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 19::

E D C B A
D C B A
C B A
B A
A
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (char i='E';i>='A';i--){
            for (char j=i;j>='A';j--){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 20::

A
B A
C B A
D C B A
E D C B A
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (char i='A';i<='E';i++){
            for (char j=i;j>='A';j--){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 21::

A B C D E
A B C D
A B C
A B
A
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (char i='E';i>='A';i--){
            for (char j='A';j<=i;j++){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 22::

A B C D E
B C D E
C D E
D E
E
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (char i='A';i<='E';i++){
            for (char j=i;j<='E';j++){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 23::

E
D E
C D E
B C D E
A B C D E
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        for (char i='E';i>='A';i--){
            for (char j=i;j<='E';j++){
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Pattern Program 24::

Enter the number: 5
    *
   **
  ***
 ****
*****
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n=sc.nextInt();
        int i,j;
        for ( i=1;i<=n;i++){
            for ( j=1;j<=n-i;j++)
                System.out.print(" ");
            for (j=1;j<=i;j++)
                System.out.print("*");
            System.out.println();
        }
    }
}

Pattern Program 25::

Enter the number: 5
* * * * *
* * * *
* * *
* *
*
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n=sc.nextInt();
        int i,j;
        for ( i=1;i<=n;i++){
            for ( j=n;j>=i;j--)
                System.out.print("*");
            System.out.println();
        }
    }
}

Pattern Program 26::

Enter the number: 5
*****
 ****
  ***
   **
    *
import java.util.Scanner;
public class Patterns {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n=sc.nextInt();
        int i,j;
        for ( i=1;i<=n;i++){
            for ( j=1;j<i;j++)
                System.out.print(" ");
            for (j=n;j>=i;j--)
                System.out.print("*");
            System.out.println();
        }
    }
}