Answer:
Yes — if the user asks for five lines, a loop should count 1, 2, 3, 4, 5.
Counting Loop for Lines
Here is the skeleton program, with the usual blanks. The skeleton focuses on getting the number of lines right, and leaves the rest for later.
import java.util.Scanner;
//
class StarBlock
{
public static void main (String[] args )
{
Scanner scan = new Scanner( System.in );
int numRows; // the number of Rows
int numStars; // the number of stars per row
int row; // current row number
// collect input data from user
System.out.print( "How many Rows? " );
numRows = scan.nextInt() ;
System.out.print( "How many Stars per Row? " );
numStars = scan.nextInt() ;
while ( )
{
(more statements go here )
}
}
}
Some of the information collected from the user is not used yet. First concentrate on looping the correct number of times.
QUESTION 19:
Fill in the three blanks. Select from the following:
row <= numRows row = 1; row = row + 1;