1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
monitta
4 years ago
7

Write an application in which you declare an array of eight first names. Write a try block in which you prompt the user for an i

nteger and display the name in the requested position. Create a catch block that catches the potential ArrayIndexOutOfBoundsException thrown when the user enters a number that is out of range. The catch block also should display the error message Subscript out of range.
Computers and Technology
1 answer:
meriva4 years ago
4 0

Answer:

import java.util.*;

public class Main

{

public static void main(String[] args) {

   

    String[] names = {"Ted", "Marshall","Lily", "Barney","Robin", "Stella", "Ranjit", "Wendy"};

 Scanner input= new Scanner(System.in);

 int i;

 try

 {

  System.out.print("Enter an integer(1 to 8) to display a name in that position: ");

  i = input.nextInt();

  i = i - 1;

  System.out.println(names[i]);

  input.close();

 }

 catch (ArrayIndexOutOfBoundsException e){

  System.out.println("Number is out of range!");

 }

   

}

}

Explanation:

Initialize an array containing 8 names

Inside the try block:

Ask the user for a number

Decrease the number by 1, so that it corresponds to the array index

Print the name in that position

Inside the catch block, define an ArrayIndexOutOfBoundsException that will print the error message, if the user enters a number that is not in the range

You might be interested in
If a security officer is non-commissioned officer, he can carry a baton on duty if he went through a training class
GaryK [48]
Baton training it is in the question 

5 0
4 years ago
What does Pentium means?:/
netineya [11]
Pentium is just a brand of a CPU chips from Intel that is usually in your laptops or chromebooks. It's used for general purpose computing. Produced by Intel since 1993. 
4 0
3 years ago
Read 2 more answers
On a network, a(n) ________ helps prevent data packets from colliding with each other.
KATRIN_1 [288]
On a network, a(n) Switches helps prevents data packets from colliding with each other.
4 0
3 years ago
Computer programs typically perform three steps: input is received, some process is performed on the input, and output is produc
-Dominant- [34]
True. Most basic programs follow this structure.
6 0
1 year ago
Assume that x and y are boolean variables and have been properly initialized. !(x || y) || (x || y) The result of evaluating the
LenaWriter [7]

Answer:

The answer is "Always true "

Explanation:

Following are the program to this question:

#include <iostream>//header file

using namespace std;

int main()//main method

{

bool x=true;//defining bool variable x and assign value

bool y=false;//defining bool variable y and assign value

if(!(x || y) || (x || y))//use given condition with if block

{

   cout<<"True";//print true message

}

else//defining else block

{

   cout<<"false";//print false message

}

   return 0;

}

In the above code two bool variable is declared, that hold ture and false, and used in the given expression with the condition statement, that checks the given value. In the code the logical gate OR gate that always print the true value.

3 0
3 years ago
Other questions:
  • Using a second hash function to compute increments for probe increments is called
    15·1 answer
  • If you were optimizing for performance and wanted to support potentially adding many new elements to an adt, then:
    12·1 answer
  • Which of the following applies to a DNS caching server? (Choose all that apply.)
    6·1 answer
  • _______ are unprocessed facts that a computer feeds on.
    5·1 answer
  • Suppose two hosts, A and B, are separated by 15,000 kilometers and are connected by a direct link of R = 5 Mbps. Suppose the pro
    11·1 answer
  • Which model represents scenarios thatchange over time?
    8·1 answer
  • B.
    12·1 answer
  • my pc wants to run the highest graphics even though I restart it everyday and it gets around 10 fps and I have a 1080 Nvidia gra
    7·1 answer
  • Area Triangolo Rettangolo in c++
    6·1 answer
  • G. What are handheld computers? Write its types.​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!