Java Program: Creating a Stylish 'Java' Pattern with Letters

java

Output -


Welcome to another exciting Java programming adventure! In this blog post, we'll explore how to create a visually appealing 'Java' pattern using simple text output.

1) Simple Solution

class First{
    public static void main(String[] args) {
        System.out.println("  J    a   v     v  a");
        System.out.println("  J   a a   v   v  a a");
        System.out.println("J J  aaaaa   V V  aaaaa");
        System.out.println("JJJ  a     a   V  a     a");
     }
}

2) Simple Solution

class First{
    public static void main(String[] args) {
                for( int i = 0; i < 4; i++ ){
                    printLetterJ(i);
                    printLetterA(i);
                    printLetterV(i);
                    printLetterA(i);
                    System.out.println();
                }
            }
            public static void printLetterA(int rowIndex){
                int startIndex = 3 - rowIndex;
                int endIndex = 3 + rowIndex;
                boolean printwhatsBetween = false;
                if( rowIndex == 2 ){
                    printwhatsBetween = true;
                }

                for( int j = 0; j < 7; j++ ){
                    if( j == startIndex || j == endIndex || ( j > startIndex && j < endIndex && printwhatsBetween ) ){
                        System.out.print( "a" );
                    }
                    else{
                        System.out.print(" ");
                    }
                }
            }
            public static void printLetterV( int rowIndex ){
                int startIndex = rowIndex;
                int endIndex = 6 - rowIndex;
                for( int j = 0; j < 7; j++ ){
                    if( j == startIndex || j == endIndex ){
                        System.out.print("v");
                    }
                    else{
                        System.out.print(" ");
                    }
                }
            }
            public static void printLetterJ( int rowIndex ) {
                char[][] jArray = {{' ', ' ', ' ', 'J'},
                        {' ', ' ', ' ', 'J'},
                        {'J', ' ', ' ', 'J'},
                        {' ', 'J', 'J', ' '}};
                for (int j = 0; j < 4; j++) {
                    System.out.print(jArray[rowIndex][j]);
                }
                System.out.print(" ");
            }
}
    }

3) Simple Solution

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

        for (int i = 1; i <=97; i++) {
            if(i == 4 || i == 27 || i == 48
                    || i == 51 || i == 74 || i == 75) {
                System.out.print("J");
            } else if (i == 9 || i == 22 || i == 31
                    || i == 33 || i == 44 || i == 46
                    || i >= 54 && i <= 58
                    || i >= 67 && i <= 71
                    || i == 78 || i == 84 || i == 91
                    || i == 97) {
                System.out.print("a");
            } else if (i == 13 || i == 19 || i == 37
                    || i == 41) {
                System.out.print("v");
            } else if (i == 62 || i == 64 || i == 88) {
                System.out.print("V");
            } else if(i == 23 || i == 47 || i == 72){
                System.out.print("\n");
            } else {
                System.out.print(" ");
            }
        }
    }
}

4) Simple Solution

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

        for (int i = 1; i <=97; i++) {
            if(i == 4 || i == 27 || i == 48
                    || i == 51 || i == 74 || i == 75) {
                System.out.print("J");
            } else if (i == 9 || i == 22 || i == 31
                    || i == 33 || i == 44 || i == 46
                    || i >= 54 && i <= 58
                    || i >= 67 && i <= 71
                    || i == 78 || i == 84 || i == 91
                    || i == 97) {
                System.out.print("a");
            } else if (i == 13 || i == 19 || i == 37
                    || i == 41) {
                System.out.print("v");
            } else if (i == 62 || i == 64 || i == 88) {
                System.out.print("V");
            } else if(i == 23 || i == 47 || i == 72){
                System.out.print("\n");
            } else {
                System.out.print(" ");
            }
        }
    }
}

5) Simple Solution 

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

        for (int i = 0; i < 5; i++) {
            for(int j = 0 ; j<25 else="" i="=2)" if="" j="" system.out.print="">=5 && j<=9) || (j>=18 && j<=23) )
                        System.out.print("A");
                    else if(j==13 || j==15)
                        System.out.print("V");
                    else
                        System.out.print(" ");
                }
                else if(i==3) {
                    if(j==2 || j==1)
                        System.out.print("J");
                    else if(j==4 || j==10 || j==17 || j==24)
                        System.out.print("A");
                    else if(j==14)
                        System.out.print("V");
                    else
                        System.out.print(" ");
                }
                else
                    System.out.print("");
            }
            System.out.println(" ");
        }
    }
}
Next Post Previous Post
No Comment
Add Comment
comment url