Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. The following diagram represents a String array with 5 elements: Jocko's Chun's Leftovers Log Cabins Velzyland

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

Step by Step Solution

3.45 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

1st problem solution If u want to edit the String Velzyland you should go with index number 4 Reason ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Chemistry The Central Science

Authors: Theodore Brown, Eugene LeMay, Bruce Bursten, Catherine Murphy, Patrick Woodward

12th edition

321696727, 978-0132175081, 978-0321696724

More Books

Students also viewed these Programming questions