I'm currently trying to display a filled asterisk square and a hollow asterisk :
********** **********
********** * *
********** * *
********** * *
********** **********
Instead, I'm getting this output:
**********
**********
**********
**********
**********
**********
* *
* *
* *
**********
I'm not so sure how to make it side by side instead of up and down. Do I have to put the hollow nested loop inside the filled loop or do I have to do something else? Here is my code:
public class doubleNestedLoops {
public static void main(String[] args) {
//Filled Square
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 10; j++) {
System.out.print("*");
}
System.out.println();
}
//Hollow Square
for (int j = 1; j <= 5; j++) {
for (int i = 1; i <= 10; i++) {
if (j == 1 || j == 5 || i == 1 || i == 10) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…