Pattern Program in Java Set – 3

1526
Pattern Program Set-3
Advertisement

Pattern Programs can be Number Pattern,Alphabets or Special Symbols.Pattern Program are frequently asked in Interviews for Freshers because the Organization/Company want to check Candidate’s Logical Skills as well as Coding Skills.This post is the collection of some similar shape of pattern with different types.I hope this post will definitely help you.


Pattern 1:

*****
****
***
**
*

Pattern Program in Java:

import java.util.Scanner;

class Pattern_1 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of rows : ");

        int n = sc.nextInt();

        for(int i = n;i >= 1;i--){

            for(int j = i;j >= 1;j--){

                System.out.print("*");

            }

            System.out.println();
        }
    }
}

Output:

Enter the number of rows : 
5

*****
****
***
**
*

Pattern 2:

11111
2222
333
44
5

Pattern Program in Java:

import java.util.Scanner;

class Pattern_2 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of rows : ");

        int n = sc.nextInt();

        for(int i = 1;i <= n;i++){

            for(int j = 1;j <= (n-i+1);j++){

                System.out.print(i);

            }

            System.out.println();
        }
    }
}
Output:
Enter the number of rows : 
5

11111
2222
333
44
5

Pattern 3:

12345
1234
123
12
1

Pattern Program in Java:

import java.util.Scanner;

class Pattern_3 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of rows : ");

        int n = sc.nextInt();

        for(int i = 1;i <= n;i++){

            for(int j = 1;j <= (n-i+1);j++){

                System.out.print(j);

            }

            System.out.println();
        }
    }
}

Output:

Enter the number of rows : 
5

12345
1234
123
12
1

Pattern 4:

12345
2345
345
45
5

Pattern Program in Java:

import java.util.Scanner;

class Pattern_4 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of rows : ");

        int n = sc.nextInt();

        for(int i = 1;i <= n;i++){

            for(int j = i;j <= n;j++){

                System.out.print(j);

            }

            System.out.println();
        }
    }
}

Output:

Enter the number of rows : 
5

12345
2345
345
45
5

Pattern 5:

55555
4444
333
22
1

Pattern Program in Java

import java.util.Scanner;

class Pattern_5 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of rows : ");

        int n = sc.nextInt();

        for(int i = n;i >= 1;i--){

            for(int j = 1;j <= i;j++){

                System.out.print(i);

            }

            System.out.println();
        }
    }
}

Output:

Enter the number of rows : 
5

55555
4444
333
22
1

Pattern 6:

54321
5432
543
54
5

Pattern Program in Java:

import java.util.Scanner;

class Pattern_6 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of rows : ");

        int n = sc.nextInt();

        for(int i = 1;i <= n;i++){

            for(int j = n;j >= i;j--){

                System.out.print(j);

            }

            System.out.println();
        }
    }
}

Output:

Enter the number of rows : 
5

54321
5432
543
54
5

Pattern 7:

54321
4321
321
21
1

Pattern Program in Java:

import java.util.Scanner;

class Pattern_7 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number of rows : ");

        int n = sc.nextInt();

        for(int i = 1;i <= n;i++){

            for(int j = (n-i+1);j >= 1;j--){

                System.out.print(j);

            }

            System.out.println();
        }
    }
}

Output:

Enter the number of rows : 
5

54321
4321
321
21
1

Pattern 8:

AAAAA
BBBB
CCC
DD
E

Pattern Program in Java:

import java.util.Scanner;

class Pattern_8 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the word to limit the Pattern (In Capitals) : ");

        //There is difference A-Z in Capitals and a-z in a small case
        //Enter input carefully

        char c = sc.next().charAt(0);

        for(char i = 'A';i <= c;i++){

            for(int j = c-i+1;j > 0;j--){

                System.out.print(i);

            }

            System.out.println();
        }
    }
}

Output:

Enter the word to limit the Pattern (In Capitals) : 
E

AAAAA
BBBB
CCC
DD
E

Pattern 9:

ABCDE
ABCD
ABC
AB
A

Pattern Program in Java:

import java.util.Scanner;

class Pattern_9 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the word to limit the Pattern (In Capitals) : ");

        //There is difference A-Z in Capitals and a-z in a small case
        //Enter input carefully

        char c = sc.next().charAt(0);

        for(int i = 1;i <= c-'A'+1;i++){

            for(char j = 'A';j<=c-i+1;j++){

                System.out.print(j);

            }

            System.out.println();
        }
    }
}

Output:

Enter the word to limit the Pattern (In Capitals) : 
E

ABCDE
ABCD
ABC
AB
A

Program 10:

ABCDE
BCDE
CDE
DE
E

Pattern Program in Java:

import java.util.Scanner;

class Pattern_10 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the word to limit the Pattern (In Capitals) : ");

        //There is difference A-Z in Capitals and a-z in small case
        //Enter input carefully

        char c = sc.next().charAt(0);

        for(char i = 'A';i <= c;i++){

            for(char j = i;j <= c;j++){

                System.out.print(j);

            }

            System.out.println();
        }
    }
}

Output:

Enter the word to limit the Pattern (In Capitals) : 
E

ABCDE
BCDE
CDE
DE
E

Pattern 11:

EEEEE
DDDD
CCC
BB
A

Pattern Program in Java:

import java.util.Scanner;

class Pattern_11 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the word to limit the Pattern (In Capitals) : ");

        //There is difference A-Z in Capitals and a-z in a small case
        //Enter input carefully

        char c = sc.next().charAt(0);

        for(char i = c;i >= 'A';i--){

            for(char j = i;j>='A';j--){

                System.out.print(i);

            }

            System.out.println();
        }
    }
}
Output:
Enter the word to limit the Pattern (In Capitals) : 
E

EEEEE
DDDD
CCC
BB
A

Pattern 12:

EDCBA
EDCB
EDC
ED
E

Pattern Program in Java:

import java.util.Scanner;

class Pattern_12 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the word to limit the Pattern (In Capitals) : ");

        //There is difference A-Z in Capitals and a-z in a small case
        //Enter input carefully

        char c = sc.next().charAt(0);

        for(int i = 'A';i <= c;i++){

            for(char j = c;j >= i;j--){

                System.out.print(j);

            }

            System.out.println();
        }
    }
}

Output:

Enter the word to limit the Pattern (In Capitals) : 
E

EDCBA
EDCB
EDC
ED
E

Pattern 13:

EDCBA
DCBA
CBA
BA
A

Pattern Program in Java:

import java.util.Scanner;

class Pattern_13 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the word to limit the Pattern (In Capitals) : ");

        //There is difference A-Z in Capitals and a-z in a small case
        //Enter input carefully

        char c = sc.next().charAt(0);

        for(char i = c;i >= 'A';i--){

            for(char j = i;j >= 'A';j--){

                System.out.print(j);

            }

            System.out.println();
        }
    }
}
Output:
Enter the word to limit the Pattern (In Capitals) : 
E

EDCBA
DCBA
CBA
BA
A

I hope you will find these Pattern Programs very helpful for your preparation.If you have doubts regarding these programs comment below or directly mail us.We will happy to help you.

If you need more Pattern Programs for Practice.Please follow the Link : 

Pattern Programs

Learn the below things: