Question: Task 1: What kind of errors are is caused by the following code, if any? How would we fix them? Note: Some errors may be

Task 1: What kind of errors are is caused by the following code, if any?

How would we fix them?

Note: Some errors may be caused before execution (before you run

the program). In this case, list the error written in NetBeans

when you hover over the problem.

//Task 1a.

String[] arr = new String[10];

arr[10] = "This is a String";

Exception:__________________________________________________________

What caused the error:______________________________________________

How to Fix It:______________________________________________________

--------------------------------------------------------------------

//Task 1b.

String[] arr = new String[-1];

Exception:__________________________________________________________

What caused the error:______________________________________________

How to Fix It:______________________________________________________

--------------------------------------------------------------------

//Task 1c.

String arr = new String[10];

Exception:__________________________________________________________

What caused the error:______________________________________________

How to Fix It:______________________________________________________

--------------------------------------------------------------------

//Task 1d.

String[] arr = new String[10];

System.out.println(arr[2].length());

Exception:__________________________________________________________

What caused the error:______________________________________________

How to Fix It:______________________________________________________

--------------------------------------------------------------------

//Task 1e.

Object x[] = new String[1];

x[0] = new Integer(0);

Exception:__________________________________________________________

What caused the error:______________________________________________

How to Fix It:______________________________________________________

--------------------------------------------------------------------

//Task 1f.

String arr[] = new String[10];

Exception:__________________________________________________________

What caused the error:______________________________________________

How to Fix It:______________________________________________________

Task 2:

Have the user store values in an array.

2a. Create a new Java project, and begin by asking the user how many

values they would like to store into an array.

2b. Initialize a global String array "data" using the input as size.

2c. Create a method called "populateArray" which will contain a loop

that asks the user to input each value and store them within the

global array "data".

2d. Use a loop to print the contents of the changed array.

Task 3:

Have the user access or modify a value in the array.

3a. Create a method called "changeArray" which will ask the user for an

index (location) in the array.

3b. Print out the value stored in the global array at the index

specified by the user .

3c. Ask the user if they would like to change that value. If so, get a

value from the user and modify "data" at the specified index to

match the user's input.

3d. Use a loop to print the contents of the changed array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!