Exam 4 (Chapters 5 & 6, mainly 8)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the value of names[4] in the following array? String[] names = {"Jeff", "Dan", "Sally", "Jill", "Allie"};

Allie (Jeff = 0, Dan = 1, Sally = 2, Jill = 3, Allie =4)

What will be the output of the following code? int[] arr = new int[9]; System.out.println(arr[0]);

0

4. public class Main { public static void main(String args[]) { int arr[][] = new int[4][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; arr[3] = new int[4]; int i, j, k = 0;

0 1 2 3 4 5 6 7 8 9 ?

What numbers does the code that follows print to the console? int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9}; for (int i = 0; i < 8; i++) { System.out.println(numbers[i]); }

1-8

2. Predict the output // file name: Main.java public class Main {public static void main(String args[]) {int arr[] = {10, 20, 30, 40, 50}; for(int i=0; i < arr.length; i++) { System.out.print(" " + arr[i]);

10, 20, 30, 40, 50

The length of the following array is int[] grades = new int[4];

4

3. class Test { public static void main(String args[]) { int arr[2]; System.out.println(arr[0]); System.out.println(arr[1]); } }

compiler error

1. Which of the following is FALSE about arrays on Java

Length of array can be changed after creation of array

Output of following Java program? class Test { public static void main (String[] args) { int arr1[] = {1, 2, 3}; int arr2[] = {1, 2, 3}; if (arr1 == arr2) System.out.println("Same"); else; System.out.println("Not Same");

Not Same

class Test { public static void main (String[] args) { int arr1[] = {1, 2, 3}; int arr2[] = {1, 2, 3}; if (arr1.equals(arr2)) System.out.println("Same"); else System.out.println("Not Same");

Not Same

Output of following Java program? import java.util.Arrays; class Test { public static void main (String[] args) { int arr1[] = {1, 2, 3}; int arr2[] = {1, 2, 3}; if (Arrays.equals(arr1, arr2)) System.out.println("Same");

Same

Which of the following, if any, is an invalid array declaration?

String[] names = new String[5]; String names[] = new String[5]; String[] names = new String[0]; all are valid

What will be the output of the following code? int[] arr = new int[9]; System.out.println(arr[9]);

error because index must be less than the higher number of the array size

Which of the following statements gets the number of integers in the array that follows? int[] customers = new int[55];

int size = customers.length;

local variable

located on the stack

new variables

stored on the heap

What is the highest index value associated with the array that follows? byte[] values = new byte[x];

x - 1 (the highest value index you can create is one less than the value you created...?)


Set pelajaran terkait

1.1 The study of life reveals common themes

View Set

الثبات على الحق - سورة الأحزاب - 1

View Set

Spelling Neighboring Countries of France (in French)

View Set

PSY 200 EXAM 4 Practice Questions

View Set

Chapter 57: Management of Patients with Burn Injury

View Set

AP Environmental - Fossil Fuels and Nuclear Energy

View Set

TX Prin. of Real Estate ONE Ch. Four 4.2

View Set

Topic 1 - Introduction to strategic Knowledge Management

View Set