KnowledgeBoat Logo

Java Pattern Programs

  • Java Nested for Loops

    Write a program in Java to display the following pattern:

    $#$#$
    $#$#
    $#$
    $#
    $


  • Java Nested for Loops

    Write a program in Java to display the following pattern:

    1 * 3 * 5 
    * 3 * 5 * 
    3 * 5 * 7 
    * 5 * 7 * 
    5 * 7 * 9
    


  • Java Nested for Loops

    Write a program in Java to display the following pattern:

    1****
    22***
    333**
    4444*
    55555
    


  • Java Nested for Loops

    Write a program in Java to display the following pattern:

    1234554321
    1234  4321
    123    321
    12      21
    1        1
    


  • Java Nested for Loops

    Write a program in Java to display the following pattern:

    12345
    2345
    345
    45
    5
    45
    345
    2345
    12345


  • Java Nested for Loops

    Using the switch statement, write a menu driven program to print the following patterns based on user's choice:

    Pattern 1:

    11
    12 22
    13 23 33
    14 24 34 44
    15 25 35 45 55

    Pattern 2:

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


  • Java Nested for Loops

    Write a menu driven program to generate pattern as follows:

    For choice 1:

    1
    2*3
    4*5*6
    7*8*9*0
    

    For choice 2:

    5****
    4###
    3**
    2#
    1
    


  • Java Nested for Loops

    Write a program to generate a triangle or an inverted triangle till n terms based upon the user's choice.

    Example 1:
    Input: Type 1 for a triangle and
    Type 2 for an inverted triangle
    Enter your choice 1
    Enter the number of terms 5
    Sample Output:
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5

    Example 2:
    Input: Type 1 for a triangle and
    Type 2 for an inverted triangle
    Enter your choice 2
    Enter the number of terms 6
    Sample Output:
    6 6 6 6 6 6
    5 5 5 5 5
    4 4 4 4
    3 3 3
    2 2
    1


  • Java Nested for Loops

    Using the switch statement, write a menu driven program for the following:

    (a) To print the Floyd's triangle:
    1
    2   3
    4   5   6
    7   8   9   10
    11 12 13 14 15

    (b) To display the following pattern:
    I
    I C
    I C S
    I C S E

    For an incorrect option, an appropriate error message should be displayed.

    View Answer

    18 Likes


  • Java String Handling

    Write a program to generate a triangle or an inverted triangle till n terms based upon the User’s choice of the triangle to be displayed.

    Example 1:
    Input: Type 1 for a triangle and
    Type 2 for an inverted triangle
    Enter your choice 1
    Enter the number of terms 5
    Sample Output:

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

    Example 2:
    Input: Type 1 for a triangle and
    Type 2 for an inverted triangle
    Enter your choice 2
    Enter the number of terms 5
    Sample Output:

    A B C D E  
    A B C D  
    A B C  
    A B  
    A
    


Showing 51 - 60 of 87 Questions