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 21:40
Develop a function to create a document in the mongodb database “city” in the collection “inspections.” be sure it can handle error conditions gracefully. a. input -> argument to function will be set of key/value pairs in the data type acceptable to the mongodb driver insert api call b. return -> true if successful insert else false (require a screenshot)
Answers: 2
question
Computers and Technology, 23.06.2019 12:30
What is the difference between the internet and the world wide web?
Answers: 1
question
Computers and Technology, 23.06.2019 22:20
What is a programming method that provides for interactive modules to a website?
Answers: 1
question
Computers and Technology, 24.06.2019 11:20
Every telecommunication setup uses two devices: one device to transmit data and one device to receive data. which device transmits frequencies to mobile phones? towers transmit frequencies to mobile phones.
Answers: 1
You know the right answer?
Exception handling to detect input String vs. Integer The given program reads a list of single-word...
Questions
question
English, 17.10.2019 20:40
Questions on the website: 13722359