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
To change the size of a field or record by dragging its border a.resize b.magnify c.label d.enlarge
4vir4ik [10]
A. Resize

By dragging the border of a field or record, you are either enlarging it or compressing it. Choices "b" and "d" are only half correct, as there is always the possibility of making it smaller. Hope this helps!
6 0
3 years ago
Read 2 more answers
20<br>Calculate the kinette energy of a body the speed<br>that will be a mass tragm​
jolli1 [7]

Answer:

20

Explanation:

4 0
3 years ago
if i were to buy one of these and plug it into a ps4 usb slot would i be able to see it on a tv? cause my hdmi slot on the ps4 i
alisha [4.7K]
It should work unless you did or bought the wrong thing
7 0
3 years ago
Read 2 more answers
A type of graph that uses horizontal bars to compare data is called a
sergiy2304 [10]
The answer is A) a bar graph

6 0
4 years ago
Read 2 more answers
Write function modifyString(origString, charsToReplace, count) that takes as input a string origString, a string charsToReplace,
laila [671]

Answer:

The code of the above program is provided below. using Python

Explanation:

<u>Code in Python 3:- </u>

def modifyString(origString,charsToReplace,count):

# Make s1 as original string

s1=origString

# Make s2 as charsToReplace string in lowercase

s2=charsToReplace.lower()

# Make s3 as charsToReplace string in uppercase

s3=s2.upper()

# Initialize answer as an empty string

ans=''

# Iterate the string upto length times

for i in range(len(s1)):

# check for chars in the string and append to the answer

if (s1[i] in s2) or (s1[i] in s3):

ans=ans+count*s1[i]

else:

ans=ans+s1[i]

# return the final string

return ans

print(modifyString("Our cat is funny","aeiou",5))    

print(modifyString("Our cat is funny","zu",3))

8 0
3 years ago
Other questions:
  • What type of device is the printer?
    13·2 answers
  • John, the network administrator of XYZ Corporation, is interested in changing the format of text from the American Standard Code
    10·1 answer
  • What analogy could you use to explain the hardware parts of a computer?
    11·1 answer
  • Choose all that apply.
    6·2 answers
  • What is the output of the following function if the array nums contains the values 1 2 3 4 5 int backwards(int nums[]) { for (x
    15·1 answer
  • Mark is the network administrator in his building and is responsible for training all the new technicians on various troubleshoo
    7·1 answer
  • What file in the user account folder stores user settings?
    8·1 answer
  • Many Web browsers allow users to open anonymous windows. During a browsing session in an anonymous window, the browser does not
    14·1 answer
  • Which statement describes a biotic factor interacting with the environment?
    5·1 answer
  • Describe how computer are used in ticket counter?​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!