import java.util.Scanner;
?
public class AssertTest
  {
        public static void main( String args[] )
        {
            Scanner input = new Scanner( System.in );
?
            System.out.print( "Enter a number between 0 and 10: " );
            int number = input.nextInt();
?
            assert ( number >= 0 && number <= 10 ) : "Invalid number: " + number;
?
           System.out.printf( "You entered %d\n", number );
       }
  }
?
The above code demonstrates the functionality of the assert statement. Explain what happens when an entered number is valid and when an entered number is out of range.

What will be an ideal response?


The user is prompted to enter a number between 0 and 10. The number is read from the command line. The assert statement determines whether the user entered a number within the valid range. If the user entered a number that is out of range, then the program reports an "Invalid number" error. Otherwise, the program proceeds normally.

Computer Science & Information Technology

You might also like to view...

Microsoft Access is a relational ________ management program

A) document B) database C) spreadsheet D) information

Computer Science & Information Technology

Social engineering impersonation means to masquerade as a real or fictitious character and then play out the role of that person on a victim.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

What can be determined by the following declaration?

``` FILE *inputData; ``` a. the file may be used exclusively for reading b. the file may be used exclusively for writing c. the file may be used for both reading and writing d. it cannot be determined e. none of the above

Computer Science & Information Technology

Which of the following is not a valid input type?

(a) select (b) radio (c) checkbox (d) password

Computer Science & Information Technology