Whatever value the user enters is then assigned to the variable radius. Refer to Figure 4-8. In this case, the user has input 23.5 and pressed the [Enter] key. The variable radius now contains the value 23.5. The user can be prompted and input accepted on the same line. To do this, a different version of the output statement is used. Use print, rather than println. The difference between the two is that println adds a new line character to move the cursor to the next line. The cursor remains on the same line with print. Using print with the same prompt and user input as in the previous example: System.out.print( "Enter the radius of the circle: " ) // using print double radius = input.nextDouble( ) the output (prompt) and user input are: Enter the radius of the circle: 23.5 Note that a space needs to be added to the end of the prompt to separate the message from the input. It is important to use the correct Scanner method for the data type being en- tered. For example, if the program attempts to read an integer using the nextInt method, but the user enters a real number or even a letter, the operation will fail. The nextInt method will generate a runtime error called an exception, and the program will stop. An exception is an error detected by a method from which it cannot recover. In this case, the exception will be InputMismatchException. Because the input does not match the data type expected by the method, the method cannot continue. With what you have learned to this point, there is not much to do if the user enters data that does not match the data type the program is attempting to read. Later in the course, ways to avoid this exception or to re- cover from it gracefully will be discussed. Prompt User input Goodheart-Willcox Publisher Figure 4-8. The program issues a prompt, and the user inputs a number as data. Copyright Goodheart-Willcox Co., Inc. Chapter 4 Variables 89