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
A B
A B C
A B C D
A B C D E
A B C D E F
A B C D E F G
class Mcqslist
{
public static void main(String args[])
{
int row, col ;
for ( row = 1 ; row <= 7 ; row++)
{
for ( col = 7; col >= row ; col--) {
System.out.print(" ");
}
for( col = 1 ; col <= row ; col++) {
System.out.print( (char)( 64 + col ) + " ");
}
System.out.print("\n");
}
}
}
Here’s what each part of the code does:
- The outer loop (for (row = 1; row <= 7; row++)) iterates over each row from 1 to 7.
- The first inner loop (for (col = 7; col >= row; col–)) prints spaces before printing the characters. The number of spaces decreases as the row number increases.
- The second inner loop (for (col = 1; col <= row; col++)) prints characters. It prints characters from ‘A’ to the current row number. (char)(64 + col) is used to convert the numerical value into its corresponding uppercase letter according to ASCII values.
- Finally, System.out.print(“\n”); moves to the next line after printing each row to create the triangular pattern.