I am learning java, using the book "Java how to program". I am solving exercises. In this actual exercise I am supposed to make a program which reads an integer from the user. The program should then display a square of asterisks (*) corresponding to the integer read from the user. F.eks user inputs the integer 3, the program should then display:
***
***
***
I try to nest a while-statement inside another, the first one to repeat the asterisks on one line, the other one to repeat this the right amount of times. Unfortunately, I only get the program to display one line. Could anyone tell me what I am doing wrong please? The code is as follows:
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++;
}
}
}