Computers and Technology, 12.10.2021 06:00 babyskitt
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 {
}
}
}
Answers: 1
Computers and Technology, 21.06.2019 20:40
Peripherals are part of the main computer. true false
Answers: 3
Computers and Technology, 23.06.2019 15:20
In a game with three frames, where will the objects on layer 1 appear? a. next to the play area b. in the middle of the game c. behind everything else d. in front of everything else
Answers: 1
Computers and Technology, 23.06.2019 17:00
The more powerful, 60 volt cables and the main power shut off on an hev are both colored orange
Answers: 1
Computers and Technology, 23.06.2019 22:20
Learning sign language is an example of a(n) learning sign language is an example of a(n)
Answers: 2
Java
Given an array of 10 names, complete the main method that outputs the name specified by the a...
Mathematics, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
History, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
Social Studies, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
Biology, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
English, 26.09.2021 01:10
Mathematics, 26.09.2021 01:10
Geography, 26.09.2021 01:10