Printing star patterns are the most frequently asked go to questions for the interviewers
for(int i = 1; i <=4; i++){
for(int j = 1; j<= 4; j++){
System.out.print("*");
}
System.out.println();
}
public static void main(String[] args) {
for(int i = 1; i <= 4; i++){
for(int j = 1; j <= i; j++){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
for(int i = 1; i<=4; i++){
for(int j = 1; j <=i; j++){
if(i>=2 && j <= i -1){
System.out.print(" ");
} else {
System.out.print("*");
}
}
System.out.println();
}
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();
for(int i =0 ;i < rows; i++){
for(int j = 0; j <rows - i - 1; j++){
System.out.print(" ");
}
for(int k= 0; k <= i; k++){
System.out.print("* ");
}
System.out.println();
}
sc.close();
}
public static void main(String[] args) {
for(int i = 1; i <= 4; i++){
for(int j = 4; j >= i ; j--){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
int count = 0;
for(int i = 1; i <= 4; i++){
for(int j =4; j>= i; j--){
if(count == 0 || count == 1 || count == 2 || count == 4 || count == 5 || count == 7){
System.out.print(" ");
} else {
System.out.print("*");
}
count++;
}
System.out.println();
}
}
public static void main(String[] args) {
for(int i = 1; i <=4; i++){
for(int j = 1; j <= i; j++){
System.out.print("*");
}
System.out.println();
}
for(int i = 1; i <=4; i++){
for(int j = 3; j >= i; j--){
System.out.print("*");
}
System.out.println();
}
}