subject

Exception handling to detect input String vs. Integer The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a String rather than an Integer. At FIXME in the code, add a try/catch statement to catch java. util. InputMismatchException, and output for the age. Ex: If the input is: Lee 18 Lua 21 Mary Beth 19 Stu 33 -1 then the output is: Lee 19 Lua 22 Mary 0 Stu 34 LAB ACTIVITY 11.6.1: LAB: Exception handling to detect input String vs. Integer 0 / 10 Name AgeChecker. java Load default template.. 5 int age: 1 import java. util. Scanner; 2 import java. util. Input MismatchException; 3 4 public class Name AgeChecker public static void main(String[] args) { 6 Scanner sehr new Scanner(System. in); 7 8 String inputName; 9 10 11 input. Name = sehr. next(); 12 while (!inputName. equals("-1")) { 13 // FIXME: The following line will throw an InputMismatchException. 14 Insert a try/catch statement to catch the exception. 15 age = sehr. nextInt(): 16 System. out. println(input. Name + " (age + 1)); 17 18 inputName = scnr. next(); 19 20 21 }

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 16:10
When copying and pasting text, the first step is move your cursor type the text select the copy command select the paste command
Answers: 2
question
Computers and Technology, 23.06.2019 15:00
Plz ( which is an example of a good url?
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
Companies that implement and apply an information system effectively can create
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
Setting up a home network using wireless connections is creating a a. vpn b. lan c. wan d. mini-internet
Answers: 2
You know the right answer?
Exception handling to detect input String vs. Integer The given program reads a list of single-word...
Questions
question
Mathematics, 10.07.2019 10:30
Questions on the website: 13722367