我正在学习java,使用本书“Java如何编程”。我正在解决练习。在这个实际的练习中,我应该创建一个从用户读取一个整数的程序。程序应该显示与用户读取的整数相对应的星号(*)。 F.eks用户输入的整数3,程序应该再显示:“While循环”不能正常工作
***
***
***
我尝试窝内另一个while语句,重复在一行中的星号的第一个,另外一个重复这个适量的时间。不幸的是,我只能让程序显示一行。有谁能告诉我我做错了吗? 的代码如下:
import java.util.Scanner;
public class Oppgave618
{
public static void main(String[] args)
{
int numberOfSquares;
Scanner input = new Scanner(System.in);
System.out.print("Type number of asterixes to make the square: ");
numberOfSquares = input.nextInt();
int count1 = 1;
int count2 = 1;
while (count2 <= numberOfSquares)
{
while (count1 <= numberOfSquares)
{
System.out.print("*");
count1++;
}
System.out.println();
count2++;
}
}
}
谢谢!这解决了它:-) – user820913
不客气。祝你好运Java! – amit