subject

Java Given an array of 10 names, complete the main method that outputs the name specified by the array index entered by the user. Use a try block to output the name and a catch block to catch any . Output the message from the exception object if an is caught. Output the first element in the array if the index is negative or the last element if the index is greater than the size of the array.
Hint: Format the exception outputs using the getMessage() method from the exception object. Do not hard code the exception messages.
Ex: If the input of the program is:
5
the program outputs:
Name: Jane
Ex: If the input of the program is:
12
the program outputs:
Exception! Index 12 out of bounds for length 10
The closest name is: Johnny
Ex: If the input of the program is:
-2
the program outputs:
Exception! Index -2 out of bounds for length 10
The closest name is: Ryley
import java. util. Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System. in);
String[] names = { "Ryley", "Edan", "Reagan", "Henry", "Caius", "Jane", "Guto", "Sonya", "Tyrese", "Johnny" };
int index;
index = scnr. nextInt();
try {
}
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 04:00
Write a method that takes in an array of point2d objects, and then analyzes the dataset to find points that are close together. be sure to review the point2d api. in your method, if the distance between any pair of points is less than 10, display the distance and the (x,y)s of each point. for example, "the distance between (3,5) and (8,9) is 6.40312." the complete api for the point2d adt may be viewed at ~pf/sedgewick-wayne/algs4/documentation/point2d.html (links to an external site.)links to an external site.. try to write your program directly from the api - do not review the adt's source code.
Answers: 1
question
Computers and Technology, 23.06.2019 12:00
What type of slide show is a dynamic and eye-catching way to familiarize potential customers with what your company has to offer? a. ole b. photo album c. brochure d. office clipboard
Answers: 2
question
Computers and Technology, 23.06.2019 17:00
What are the 12 colors of the spectrum called?
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
Column a of irma’s spreadsheet contains titles for each row, but her document is too big and will be printed three pages across. she wants to be sure that every page will be understood. what can irma do to with this problem?
Answers: 3
You know the right answer?
Java Given an array of 10 names, complete the main method that outputs the name specified by the a...
Questions
question
Mathematics, 02.02.2021 22:00
question
Mathematics, 02.02.2021 22:00
question
Mathematics, 02.02.2021 22:00
question
Mathematics, 02.02.2021 22:00
question
Mathematics, 02.02.2021 22:00
question
Arts, 02.02.2021 22:00
question
English, 02.02.2021 22:00
Questions on the website: 13722359