1. The following diagram represents a String array with 5 elements: Jocko's Chun's ...
Question:
1. The following diagram represents a String array with 5 elements:
Jocko's Chun's Leftovers Log Cabins Velzyland
If I want to edit the String "Velzyland" which index number should I access?
A. 0
B. 1
C. 2
D. 3
E. 4
F. 5
G. None of these options are correct.
2. Is there anything wrong in the following code?
//Declare and initialize variables
int access = 0;
Scanner getInput = new Scanner(System.in);
//Create array
double[] myArray = {1, 3, 19, 26};
try {
//Get user input about which array element to print
System.out.println("There are 4 elements within my array.");
System.out.println("Type 1, 2, 3, or 4 for the element you would like to print:");
access = getInput.nextInt();
//Print requested array element
System.out.print("Requested array element: ");
System.out.println(myArray[access]);
}
catch (java.util.InputMismatchException ime) {
//Print error message if user doesn't enter an int value
System.out.println("You need to enter an int value, please!");
}
A. It's a double array, but you're inserting int values.
B. System.out.print("Requested array element: "); should use System.out.println instead.
C. Try/catch is incomplete.
D. There is nothing wrong with this code. It runs fine!
E. Code doesn't print out the requested element.
F. Comments are not correctly formatted.
G. Scanner object should be called "input" or "reader"
3. I would like to store the following elements in the listed order:
"Hawai'i"
50
1415872
13.9
What kind of array should I create to store these values?
A. boolean
B. char
C. double
D. int
E. String
F. None of these options are correct.
4. Which of the following is happening in the following code?
(Choose all that apply)
String[] toDoList;
Scanner getSize = new Scanner(System.in);
Scanner getTask = new Scanner(System.in);
int size = 0;
String task = "", confirm = "";
System.out.println("How many tasks do you have to complete today?");
size = getSize.nextInt();
toDoList = new String[size];
for (int i = 0; i < toDoList.length; i++) {
System.out.println("Enter a task then press enter:");
task = getTask.nextLine();
System.out.println("This task will be added to your list:");
System.out.println("t" + task);
System.out.println("Type yes to confirm:");
confirm = getTask.nextLine();
if (confirm.equalsIgnoreCase("yes")) {
if (i != 0) {
if (toDoList[i - 1] == null) {
i--;
toDoList[i] = task;
}
else {
toDoList[i] = task;
}
}
else {
toDoList[i] = task;
}
}
else if (i == (toDoList.length - 1)) {
i--;
}
}
System.out.println("Your To Do List for today:");
for (int i = 0; i < toDoList.length; i++) {
System.out.println(toDoList[i]);
}
A. Searching array
B. Print array contents
C. Copying array
D. Sum all number values within an array
E. Initialize array with user input
F. Initialize array with random values
G. Display char array
Chemistry The Central Science
ISBN: 978-0321696724
12th edition
Authors: Theodore Brown, Eugene LeMay, Bruce Bursten, Catherine Murphy, Patrick Woodward