[英]JAVA broken while loop
How can I make a program that prompts the user to enter number of rows and columns and output figure resembling hollow rectangle (using "*") formed from these rows and columns using while loops?如何制作一个程序,提示用户输入行数和列数,并使用 while 循环从这些行和列中输出类似于空心矩形(使用“*”)的图形?
Scanner stdin = new Scanner(System.in);
System.out.println("Enter number of rows and columns: ");
int row = stdin.nextInt();
int column = stdin.nextInt();
int m = 1;
while(m <= column)
{
while(m <= row)
{
System.out.println("*\t");
}
System.out.print("*");
m++;
}
Mike you Have to use diffrent variables for difflent loop control. Mike 你必须使用不同的变量来进行不同的循环控制。
create an "n" and it should work创建一个“n”,它应该可以工作
Scanner stdin = new Scanner(System.in);
System.out.println("Enter number of rows and columns: ");
int row = stdin.nextInt();
int column = stdin.nextInt();
int m = 1;
int n = 1;
while(m <= column)
{
while(n <= row)
{
System.out.println("*\t");
n++;
}
System.out.print("*");
m++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.