write an application named badsubscript in which you declare an array of 10 first names. write a try block which you prompt the user for an interger 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 should also display an error message. save the file as badsubscriptcaught.java

Answers

Answer 1

Answer:

Here is some code that works for me:

import java.util.Scanner;

public class badsubscriptcaught {

   public static void main(String[] args) {

       Scanner scanner = new Scanner(System.in);

       String[] names = {"Jake", "Jack", "Jacob", "Ben", "Liam", "Noah", "Oliver", "William", "Elijah", "James"};

       int number = Integer.parseInt(scanner.nextLine());

       try{

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

       }catch (ArrayIndexOutOfBoundsException  exception){

           System.out.println(exception + " isn't a vailid value.");

       }

   }

}

Answer 2

Exceptions are used to prevent a program from crashing, by managing the error or bugs.

The program in Java where comments are used to explain each line is as follows:

import java.util.Scanner;

public class badsubscriptcaught{

   public static void main(String[] args) {

       //This creates a scanner object

       Scanner input = new Scanner(System.in);

       //This gets input for the index to print

       int arrayIndex = input.nextInt();

       //This initializes the array.

       //Note that, the names can be replaced

       String[] nameArray = {"Liam", "Olivia" , "Noah", "Emma", "Oliver","Ava","Elijah","Charlotte","Michael","David"};

       //This creates a try-catch exception

       try{

           //This prints the array element at the corresponding index, if the index is between 0 and 9

           System.out.println(nameArray[arrayIndex]);

       }

       //This catches the exception

       catch (ArrayIndexOutOfBoundsException  exception){

          //This prints the exception

          System.out.println(exception);

      }

  }

}

At the end of the program, the exception is printed, if any.

Read more about exceptions at:

https://brainly.com/question/14234389


Related Questions

A line graph is a great tool for showing changes over time. Why is a line graph better than other graphs at showing this type of data?

Answers

Answer:

Line graphs allow us to see overall trends such as an increase or decrease in data over time. Bar graphs are used to compare facts.

It's common to print a rotating, increasing list of single-digit numbers at the start of a program's output as a visual guide to number the columns of the output to follow. With this in mind, write nested for loops to produce the following output, with each line 60 characters wide: | | | | | | 123456789012345678901234567890123456789012345678901234567890

Answers

Answer:

The program in python is as follows:

for i in range(0,6):

   for i in range(0,9):

       print(" ",end='')

   print("|",end='')

print()

for i in range(1,61):

   print(i%10,end='')

Explanation:

See attachment for program output format

The next two instructions create a nested for loop

for i in range(0,6):

   for i in range(0,9):

This prints 9 spaces

       print(" ",end='')

This prints a vertical line at the top of the end of the spaces printed

   print("|",end='')

This prints a new line

print()

This iterates from 1 to 60

for i in range(1,61):

This prints 1, 2, 3....9, then 0, 6 times on a straight line

   print(i%10,end='')

OBJECTIVE QUESTIONS
1. In a computer keyboard the Alt, Ctrl, Shift, Del & Insert
keys are known as

Answers

Answer:

A modifier

Explanation:

because this modified a computer keyboard

You should adhere to the Windows standards when designing an interface because that consistency will ______________. a. give your interface a familiar look to the user b. make your interface easier to learn c. make your interface easier to use d. All of the above

Answers

Answer:

that's c I think

Explanation:

just guessed

Click this link to view O*NET’s Tasks section for Psychiatrists. Note that common tasks are listed toward the top, and less common tasks are listed toward the bottom. According to O*NET, what are some common tasks performed by Psychiatrists? Select four options.

Answers

Answer:its 2.3.5.6

Explanation: i just did it on edge

Answer:

B,C,E,F

Explanation:

Cuz i said so

PLEASE HELP ITS CODING AND I INCLUDED A SCREENSHOT OF WHAT TO DO

Answers

Answer:

I need to have better photos in order to assist you...

Explanation:

I will attempt to get back with you if you can provide more clearer photos.

num1 = float(input("Enter your first number: "))

num2 = float(input("Enter your second number: "))

operation = input("What operation would you like to do? Type: add, subtract, multiply, or divide. ")

def add(n, n1):

   return n + n1

def subtract(n, n1):

   return n - n1

def multiply(n, n1):

   return n*n1

def divide(n, n1):

   return n/n1

if operation.lower() in ["add", "+"]:

   result = add(num1, num2)

   print(num1,"+",num2,"=",result)

elif operation.lower() in ["subtract", "-"]:

   result = subtract(num1, num2)

   print(num1,"-",num2,"=",result)

elif operation.lower() in ["multiply", "*"]:

   result = multiply(num1, num2)

   print(num1, "*", num2, "=", result)

elif operation.lower() in ["divide", "/"]:

   result = divide(num1, num2)

   print(num1, "/", num2, "=", result)

else:

   print("Not a valid operation.")

I wrote my code in python 3.8. I hope this helps.

The objective of this task is to use Scapy to estimate the distance, in terms of number of routers, between your VM and a selected destination. This is basically what is implemented by the traceroute tool. In this task, we will write our own tool. The idea is quite straightforward: just send an packet (any type) to the destination, with its Time-To-Live (TTL) field set to 1 first. This packet will be dropped by the first router, which will send us an ICMP error message, telling us that the time-to-live has exceeded. That is how we get the IP address of the first router. We then increase our TTL field to 2, send out another packet, and get the IP address of the second router. We will repeat this procedure until our packet finally reach the destination. It should be noted that this experiment only gets an estimated result, because in theory, not all these packets take the same route (but in practice, they may within a short period of time). The code in the following shows one round in the procedure. a = IP() a.dst = ’1.2.3.4’ a.ttl = 3 b = ICMP() send(a/b) If you are an experienced Python programmer, you can write your tool to perform the entire procedure automatically. If you are new to Python programming, you can do it by manually changing the TTL field in each round, and record the IP address based on your observation from Wireshark. Either way is acceptable, as long as you get the result.

Answers

Answer:

answer b

is correct

You are the systems administrator for a large trust company. Most of the Linux servers in the company host databases that are accessed frequently by company employees. One particular Linux server has been reported as being very slow today. Upon further investigation using the top utility, you have found a rogue process that is wasting a great deal of system resources. Unfortunately, the rogue process is a database maintenance program and should be killed with caution. Which kill signal would you send this process and why? If the rogue process traps this signal, which other kill signals would you try? Which command could you use as a last resort to kill the rogue process?​

Answers

Answer:

soo long this one is ufff

V. Write a program in python for the following:
[10]
a) Jennifer wants to carpet her new room with pink carpet. Create a program that will ask the user for the two
dimensions of a room (length and width) and then calculate the area of the room, (length x width), before
finally displaying the answer​

Answers

Answer:

length = input("length of room:  ")

width = input("Width of room:  ")

Area = float(length) * float(width)

print("Area of room is: ", Area)

Select the correct answer.
A computer using a connectionless network protocol sends too many data packets to another computer, causing loss of a few packets. As a result, the message appears jumbled to the user at the destination computer. How does TCP overcome this issue?
A.
by using flow control
B.
by using cables
C.
by using terminals
D.
by using a larger IP address
Please only answer if you are 100% sure

Answers

Answer:

D by using a larger IP address correct

Explanation:

Correct answer I hope this helps you :)

The following code will not display the results expected by the programmer. Can you find the error? Declare Real lowest, highest, average Display "Enter the lowest score." Input lowest Display "Enter the highest score." Input highest Set average = low + high / 2 Display "The average is ", average, "."

Answers

Based on the information given, the first error in the code is that the Variable name is lowest, NOT low, and Set average = low + high / 2.

How to find the error in the code.

For Error 2: Variable name is highest, NOT high and Set average = low + high / 2

For Error 3 : Set average = low + high / 2. Thus, you will need to add the lowest and highest, then perform the division by 2

Set average = (lowest + highest) / 2 is the the correct statement.

Learn more about codes on:

https://brainly.com/question/25875879

Pls awnser I will mark brainliest math

Answers

It’s 34....!!!! i did this before

Answer:

2788 or 116

Explanation:

What are some ways you can work with templates? Check all that apply.
A. creating a new template from scratch
B. scanning a template from a printed page
C. using many different templates in one document
D. using a preexisting template
E. modifying a preexisting template

Answers

What are some ways you can work with templates? Check all that apply.

Answer: (A,D,E) see picture below for help also.

Answer:

Look at the other answer that guy knows what he is talking about

Explanation:

What is the primary reason for compressing video files?

increase frames per second

increase bit rate

decrease file size

decrease playback delay

Answers

Answer:

Decrease file size

Explanation:

This goes for almost every file you compress. If you compress it, you try to decrease the storage space it takes up as a way to make it more portable. After a compressed file is extracted, it does not have many effects on the state of the extracted file.

Answer:C

Explanation:Decrease file size

What is a feature of Accenture’s myNav platform?

A. supports a more responsive, cost-efficient, and secure workplace platform for project deployment and full upgrades.
B. powers a highly automated, data-driven, and low-risk approach to adopting and maintaining MS Office suites
C.helps assess, architect, and simulate Cloud solutions to determine the right Cloud architecture based on our clients’ business needs
D. enhances ability to innovate, boost business results, and speed up a client’s journey to intelligent enterprises
D.

Answers

A. because I said so dummy

One feature of Accenture’s myNav platform is that it:

C. Helps assess, architect, and simulate Cloud solutions to determine the right Cloud architecture based on our clients’ business needs

According to the given question, we are asked to state one feature of Accenture’s myNav platform and how it affects the cloud computing for businesses.

As a result of this, we can see that this Accenture’s myNav platform is designed to help businesses navigate through their cloud solutions so that they can choose the package that would meet their client's business needs.

Therefore, the correct answer is option C

Read more here:

https://brainly.com/question/25675206

The Stability and Growth Part has to do with _____.


bank reserves

the Economic and Monetary Union

U.S. trade

global money market

Answers

Answer:

The Stability and Growth Pact (SGP) is an agreement, among the 27 member states of the European Union, to facilitate and maintain the stability of the Economic and Monetary Union (EMU). ... The purpose of the pact was to ensure that fiscal discipline would be maintained and enforced in the EMU.

Explanation:

follow me for more

True or False
humans shed skin in their sleep (pwease fweinds onwy answer)

Answers

Answer:

Not all people but sometimes it happens

Issues in plagiarism and copyright when blogging can be prevented. True or false​

Answers

Answer:

It’s false

Explanation:

I can’t explain it’s too confusing

Exercise 3.7.1: Proving statements about odd and even integers with direct proofs. info About Each statement below involves odd and even integers. An odd integer is an integer that can be expressed as 2k 1, where k is an integer. An even integer is an integer that can be expressed as 2k, where k is an integer.

Answers

The question is incomplete. The complete question is :

Each statement below involves odd and even integers. An odd integer is an integer that can be expressed as 2k+1, where k is an integer. An even integer is an integer that can be expressed as 2k, where k is an integer. Prove each of the following statements using a direct proof. (a) The sum of an odd and an even integer is odd. (b) The product of two odd integers is an odd integer.

Solution :

Odd number integers = 2k + 1, where k is integer

Even number integer = 2k

a). Odd integer + even integer

  = 2k + 1 + 2k

 = 4k + 1

  = 2(2k) + 1

Let 2k = t, where t is integer

   = 2t + 1

  = Odd integer by definition

If number is 2t + 1 where t belongs to integer, then it is odd integer.

Hence proved.

b). Product of two odd integers :  [tex]$2k_1 + 1,\ \ 2k_2 +1 $[/tex]   where [tex]$k_1, k_2 $[/tex] belongs to integer.

[tex]$(2k_1+1)(2k_2+1)= 4k_1k_2+2k_1+2k_2+1$[/tex]

[tex]$2(2k_1k_2)+2(k_1+k_2)+1$[/tex]

Let [tex]$2k_1k_2 = a$[/tex] and [tex]$k_1+k_2 = b $[/tex]

here, a and b belongs to integers since [tex]$k_1$[/tex] and [tex]$k_2$[/tex] are integers.

We get:

2a+2b+1

= 2(a+b)+1

= 2l + 1,             Let (a+b)=l and l belongs to integers.

It is odd integer by definition.

Hence proved.

 

Logistic Regression is a type of __________ problem.

Answers

Answer:

Logistic Regression is used to solve the classification problems, so it’s called as Classification Algorithm that models the probability of output class. It is a classification problem where your target element is categorical

Explanation:

The answer is "classification" because the named the Classification Algorithm.

It was used to solve classification difficulties. You are faced with a categorization situation wherein your goal component is a category.In the presence of more than one dependent variable, it's being used to calculate odds ratios. The binomial dependent variables render this approach similar to multiple linear regression. In the end, each variable's impact on a particular event's odds ratio is calculated.

Learn more:

Logistic Regression: brainly.com/question/20363984

During critical thinking, the evaluation of information should use
some emotions
O True
O False

Answers

False any critical thinking shouldn’t involve emotions
Im pretty sure it’s false

of what is famous Ted Nelson?​

Answers

Answer:

Nelson proposed a system where copying and linking any text excerpt, image or form was possible.

Explanation:

Ted Nelson is one of the theoretical pioneers of the world wide web who is best known for inventing the concept of hypertext and hypermedia in the 1960s. As one of the early theorists on how a networked world would work.

How I know:

I goggle it.

What are the paparazzi?
O A. Professional artists hired by stars for portraits
B. Tabloids that expose celebrities acting rudely
O C. Fans who watch videos of stars doing silly things
O D. Photographers who follow stars to take pictures

Answers

Answer:

d.photographers who follow stars to take pictures

In a block of addresses we know the IP address of one host is Roll no. Roll no. Roll no. Roll no./20.What is the first address and the last address of this block? Find the number of addresses in the block?
Hint: if your roll no is 33 then your ip address will look like this: 33.33.33.33/20

Answers

Answer:

If there’s one topic that trips people up (both new and experienced) in the networking industry, it is that of Subnetting.

One of the reasons this happens is that one has to perform (mental) calculations in decimal and also binary. Another reason is that many people have not had enough practice with subnetting.

In this article, we will discuss what Subnetting is, why it came about, its usefulness, and how to do subnetting the proper way. To make this article as practical as possible, we will go through many examples.

Note: While subnetting applies to both IPv4 and IPv6, this article will only focus on IPv4. The same concepts explained here can be applied to IPv6. Moreover, subnetting in IPv6 is more of a want rather than a necessity because of the large address space.

IP address network

For example, any traffic with a destination IP address of 192.168.1.101 will be delivered to PC1, while traffic addressed to 192.168.1.250 will be delivered to SERVER.

Note: This is an oversimplification of things just for understanding sake and refers to Unicast (one-to-one) IPv4 addresses. Traffic sent to Multicast (one-to-many) and Broadcast (one-to-all) IP addresses can be delivered to multiple devices. Also, features like Network Address Translation (NAT) allow one IP address to be shared by multiple devices.

To help your understanding of IP addresses and subnetting, you need to resolve the following fact in your head: Computers think in binary, that is, 0s and 1s. Therefore, even though we see an IP address represented like 192.168.1.250, it is actually just a string of bits – 32 bits in total for IPv4 addresses.

To make them more readable for humans, IPv4 addresses are represented in dotted decimal notation where the 32 bits are divided into 4 blocks of 8 bits (also known as an octet), and each block is converted to a decimal number.

For example, 01110100 in binary is 116 in decimal:

A unicast IPv4 address such as 192.168.1.250 can be divided into two parts: Network portion and Host ID. So what does this mean? Well, IPv4 addresses were originally designed based on classes: Class A to Class E. Multicast addresses are assigned from the Class D range while Class E is reserved for experimental use, leaving us with Class A to C:

Class A: Uses the first 8 bits for the Network portion leaving 24 bits for host IDs. The leftmost bit is set to “0”.

Class B: Uses the first 16 bits for the Network portion leaving 16 bits for host IDs. The two leftmost bits are set to “10”.

Class C: Uses the first 24 bits for the Network portion leaving 8 bits for host IDs. The three leftmost bits are set to “110”.

Note: The range of Class A is actually 1-126 because 0.x.x.x and 127.x.x.x are reserved.

With these classes, a computer/device can look at the first three bits of any IP address and determine what class it belongs to. For example, the 192.168.1.250 IP address clearly falls into the Class C range.

Looking at the Host ID portion of the classes, we can determine how many hosts (or number of individual IP addresses) a network in each class will support. For example, a Class C network will ideally support up to 256 host IDs i.e. from 00000000 (decimal 0) to 11111111 (decimal 255). However, two of these addresses cannot be assigned to hosts because the first (all 0s) represents the network address while the last (all 1s) represents the broadcast address. This leaves us with 254 host IDs. A simple formula to calculate the number of hosts supported

Explanation: Final answer is Start address: 192.168.58.0 + 1 = 192.168.58.1

End address: 192.168.58.16 – 2 = 192.168.58.14

Broadcast address: 192.168.58.16 – 1 = 192.168.58.15

True or False? A three shot is a series of any three individual
camera shots.

Answers



True. A three shot is a series of any three individual camera shot ..

Please hellppp,is a yr 9 question

Answers

Answer:

See picture below.

You want to read input from the user to know how many apples they would like
to buy. Which statement should you use to read in a number from the user?
var applesToBuy = readLine("How many apples would you lik
e? ");
o
var applesToBuy - println("How many apples would you like?
Dj
var applesToBuy - readInt("How many apples would you like?
1);
var applesToBuy
= nextInt("How many apples would you like?
")

Answers

Answer:

var applesToBuy = readLine("How many apples would you lik

e? ");

Explanation:

It asks the user to enter answer the question and it stores the answer into the applesToBuy variable.

Its right dont worry.

In the given scenario, if we use "InputStream" class object that inputs value from the user-end, in which we use "readInt" keyword. In Java, this function of the DataInputStream class reads 4 input bytes and returns an integer value. This method takes the next 4 bits from the input stream, transforms them to integers, and would then returns.

And the wrong choice can be defined as follows:

For choice 1, it use the "readLine" method which inputs the string value.For choice 2, it use the "println" method which prints value.For choice 4, the "nextInt" method is the part of "Scanner" class.

Therefore, the answer is "Option 3", which is  "var applesToBuy - readInt("How many apples would you like?");".

Learn more:

brainly.com/question/20637377

type in computer code for Sonic the Hedgehog, does it look weird yes or no

Answers

Answer:

yes.

Explanation:

Data entered in a cell will appear in the bar, found about the worksheet
a.status Bar
b.Equation Bar
c.Formula Bar
d.Data Entry Bar

Answers

Answer:

formula bar

Explanation:

The formula bar in Excel is located next to the name box

and above the worksheet area. It displays the data stored in

the active cell. The formula bar is used to view, enter, and

edit values and formulas in cells.

____________ are the in – built functions that perform a particular pre – defined task when used in a computer program.

Answers

Answer:

System software.

Explanation:

System software are the in-built functions that perform a particular pre-defined task when used in a computer program. An example of a system software is an operating system.

An operating system (OS) is a system software pre-installed on a computing device to manage or control software application, computer hardware and user processes. Some examples of an operating system are QNX, Linux, OpenVMS, MacOS, Microsoft windows, IBM, Solaris, VM etc.

Other Questions
SOMEONE PLEASE HELP ME WITH THISSS ASAP Please help me I will give brainless and a lot of points. Which is not an example of a code?Choose the correct answer.A. a secretB. a memory from the pastC. the sign language alphabetD. the information on a credit card Which of the following was an effect of Peter Hoang being sent to a concentration camp? aHe became a doctor and helped injured and sick prisoners. bHe was given a house and a plot to grow his own vegetables. cHe had to do hard labor and was not given enough to eat. dHe was paid for his hard work and had plenty of food to eat. (this is analogies BTW) I'm really confused on this question. Suspicious is to Paranoid AS _______ is to Homesick A) nostalgic B) ecstatic C) apathetic Solve for x. 6/x+ 2/5 = 8 does sugar have ionization of ions in water Mr. Brown has 14 purple,6 blue, 10 orange face masks. What is the probability that, if selected at random. Mr. Brown will pick one of his blue face mask to wear? Find the volume of each shape shown. Show all work! Read the paragraph.This paragraph is an example ofCasper's heart sank as the sun began to set. But, justthen, he heard a small scuffling noise. Could it beMacy? After many hours searching for the family'sterrier puppy, his hope was almost gone.exposition.rising action.climax.falling action.There it was again. The same scuffling sound comingfrom behind an old fence. His feet took flight, and hisblood pounded in his ears. "Macy! he cried. "Whereare you? For the expression 6 - y + 3, determine the coefficient for the variableterm.-1036 Make x the subject of y=x/3 a bakery used 25% more butter this month than last month if the bakery used 240 kilograms of butter last month how much did it use this month can 2x-15 be factored What is a conclusion paragraph? Do you become blocked when writing? If you become blocked, what strategies do you use to deal with it? Try and determine why you are blocked, evaluate whether your strategies are effective or not. What expression is equivalent to 9(9m + 3t)? achary is buying 4 tires for his car. The table shows the prices and the advertised sales for the same type of tire at 4 tire stores.Based on the advertised sales, at which store will Zachary get the lowest price on 4 tires? Adjustments to timber management strategies meant to address long-term shortfalls will _______.a.result in immediate increases in available suppliesb.lead to initial shortfalls in timber suppliesc.initially decrease the cost of timberd.ultimately result in more expensive timber is soil a producer, decomposer, or consumer