Write a while loop that verifies that the user enters a positive integer value.

What will be an ideal response?


```
Scanner scan = new Scanner(System.in);
System.out.print("Enter a positive integer: ");
number = scan.nextInt();
while (number <= 0)
{
System.out.print("That number was not positive.");
System.out.print("Enter a positive integer: ");
number = scan.nextInt();
}

```

Computer Science & Information Technology

You might also like to view...

Consider the Set interface in the java.util package. Write preconditions and post conditions in OCL for the following operations:

The constraints below assume that the association between the list and its contained elements is called elements. a. int size() returns the number of elements in the set. b. void add(Object e) adds an object to the set. If the object is already in the set, does nothing. c. void remove(Object e) removes an object from the set d. boolean contains(Object e) returns true if the object is contained in the set.

Computer Science & Information Technology

Which of the following loops counts backwards from 20 to 10?

A. Declare Numeric countDown = 20 While countdown > 0    Display countDown    countDown = countDown - 1 End While B. Declare Numeric countDown = 20 While countdown > 10    Display countDown    countDown = countDown - 1 End While C. Declare Numeric countDown = 20 While countdown = 10    Display countDown    countDown = countDown - 1 End While D. Declare Numeric countDown = 20 While countdown > 9    Display countDown    countDown = countDown - 1 End While

Computer Science & Information Technology

int *ptNum = &miles; is ____.

A. always valid B. never valid C. only valid if miles is declared as an integer variable before ptNum is declared D. only valid if miles is declared as an array of integers before ptNum is declared

Computer Science & Information Technology

What software type is software that is distributed free of charge, but the source code is not available?

A. Open source software B. Shareware C. Close source software D. Freeware

Computer Science & Information Technology