For Java questions, I need help figuring out a few questions: (1) The indices of
ID: 3864355 • Letter: F
Question
For Java questions, I need help figuring out a few questions:
(1) The indices of an array always start with position number 0 . (a) True (b) False
(2) What is the output of the following program segment?
int[] b1 = {5, 10, 15};
System.out.println(" " + b1[1]);
(a) 0 (b) 1 (c) 10 (d) 2 (e) 5
(3) What is the output of the following program segment?
int[] b1 = { 5, 10, 15 };
System.out.println(" " + b1[2]);
(a) 0 (b) 1 (c) 5 (d) 10 (e) 15
(4) After the this code segment is executed, what will be the final value of the variable sum?
int[] arrayA = { 5, 10, 15, 20, 25 };
int sum = 1 ;
for (int i = 0; i < 5; i++)
sum = sum + arrayA[i];
System.out.println(" " + sum);
(a) 80 (b) 76 (c) 75 (d) 85 (e) 90
(5) What is the range of valid indices for the following? int[] w = new int[101];
(a) 0 - 100 (b) 1 - 101
(c) To infinity and beyond infinity (d) None of these
int[] num = new int[100];
for(int i = 0; i < 50; i++)
num[i] = i;
num[5] = 10;
num[55] = 100;
(1) What is the data type of the array above?
(a) int (b) list
(c) char (d) num
Explanation / Answer
The compiler thinks that 0 is a positive number.
we have an integer range of
-128 to 127.
here -128 to -1 are negative numbers
and 0 to 127 are positive numbers
so array starts with the 0 as index.
1 . a) true
2. c) 10
3. e) 15
4. c) 76
5. a) 0 - 100
1. a)int
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.