Best Patterns in Java Program 2024

Best Patterns in Java Program 2024″ suggests a tutorial or resource showcasing some of the most effective and visually appealing patterns achievable through Java programming in the year 2024. Here’s a description of what such a resource might include:


A
B C
D E F
G H I J
K L M N O
P Q R S T U
V W X Y Z [ \

class McqslistAZ  {
          public static void main(String args[])  {
                int  row,  col , k=1;
                   for ( row = 1 ;  row <= 7 ; row++) {
                           for( col = 1 ; col <= row ; col++) {
                                      System.out.print( ( char )( 64 + k ) + " ");
                                      k++;
                           }
                        System.out.print("\n");
                    }
          }
}

  • The outer loop (for (row = 1; row <= 7; row++)) iterates over each row from 1 to 7.
  • The inner loop (for (col = 1; col <= row; col++)) prints characters. It prints characters from ‘A’ to ‘G’ based on the value of k, which starts from 1 and increments with each iteration.
  • (char)(64 + k) converts the numerical value into its corresponding uppercase letter according to ASCII values, where ‘A’ corresponds to 65 in ASCII. So, adding 64 to k maps the numbers 1 to 7 to the characters ‘A’ to ‘G’.
  • System.out.print(“\n”); moves to the next line after printing each row to create the triangular pattern.

For more Patterns Click on Here => Pattens in Java Programs



Before converting the character the Output is:-
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28

but we Added 64 and converted it into Characters so we could get
A
B C
D E F
G H I J
K L M N O
P Q R S T U
V W X Y Z [ \

Leave a Comment