For Interview Java Patterns with Code.
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:
Solve this pattern in the Java program.
A
B B
C C C
D D D D
E E E E E
F F F F F F
G G G G G G G
class Mcqslist {
public static void main(String args[]) {
int row, col ;
for ( row = 1 ; row <= 7 ; row++ ) {
for( col = 1 ; col <= row ; col++ ) {
System.out.print( (char)( 64+ row ) +" " );
}
System.out.print("\n");
}
}
}
In this, we use Two for loop First for how many rows we need and the main logic for this is in the second loop where we change the value of every column.
for( col = 1 ; col <= row ; col++ )
in this for-loop, we can start the loop from 1 and end the loop on the row value on every next row,
System.out.print( (char)( 64+ row ) +” ” );
In this line, we print the value but first, we convert it into a character by adding 64 in the row value
if the row value is 1 then
Why we add 64 in the row :=
because by using (char)( 64+ row ) we can convert the Integer number into a character
64 is the ASCII number of the A character.