我不知道如何让星号排成行和列。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int width;
int height;
Scanner input = new Scanner(System.in);
System.out.print("Enter the width:");
width = input.nextInt();
System.out.print("Enter the height:");
height = input.nextInt();
int y = 0;
for (int x = 0; x <= width; x++){
System.out.println("*");
while (y <= height){
y++;
System.out.println("*");
}
}
}
}我试图得到一个输出,它的宽度=4英尺=4
**** ****
**** * *
**** * *
**** or ****发布于 2019-05-09 22:43:17
以下是一些帮助你解决这一问题的建议:
例如,实心正方形(编写为算法,而不是代码):
loop y once for each row {
loop x once for each column in that row {
print a '*' character
}
print a newline character (because we have finished the row)
}例如,空心正方形(编写为算法,而不是代码):
loop y once for each row {
loop x once for each column in that row {
if the current position is in the first row, last row, first column or last column
print a '*' character
otherwise
print a ' ' character
}
print a newline character (because we have finished the row)
}https://stackoverflow.com/questions/56068094
复制相似问题