Let us see a favorite pattern of interviewers – Mirrored Right Angle Triangle. This is one of the basic pattern to practice logic building before you try competitive programming.
public class Tech4Humans {
public static void main(String[] args) {
// side size of triangle
int size = 5;
for (int i = 0; i < size; i++) {
for (int j = 0; j < (size - i - 1); j++) {
System.out.print(" ");
}
for (int k = 0; k <= i; k++) {
System.out.print("*");
}
System.out.println();
}
}
Output
*
**
***
****
*****
Understand the logic carefully and try to make other patterns yourself. To debug code easily refer the article RIGHT WAY TO DEBUG CODE USING PEN AND PAPER.