Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Help! For each of the following, assume we have declared the following: i

ID: 3702638 • Letter: P

Question

Please Help!

For each of the following, assume we have declared the following: int[] arr ={1, 2, 3, 18); int[] arr2 -new int [8]; int C arr3- 11, 2), 13, 4), 15, 6}, 17, 8}, f9, 10; String s = "Hello World". Identify what the result will be, or write Compile-time or Run-time if there is a Compile-time or Run-time error: a) arr O (b) arr[arr2.length - 5 (c) s.charAt(arr.length); (d) s.charAt(arr[3); (e) s.charAt(arr[5]); (f) s.charAt(arr[1]); (g) arr3[arr.length]; (h) arr3[arr.length] [1; (i) arr3.length; G) arr310] length; (k) arr3[I].length0: (1) s.length (m) s.charAt(s.indexOf('H')); (n) s.charAt(s.indexOf(Q)) (o) s.indexOf(Q); (p) arr2[0]; (q) arr2? arr; (s) arr0- (int) s.charAt(6); (t) arr0 s.charAt (6); (u) int j= 6.0; (v) double d 7; (w) s+='q'; (x) (s + "Goodbye!").length0: (y) s == ("Hello" +" World"); (z) s.equals("Hello " + "World");

Explanation / Answer

Find the below updated code with respective result or Compile Time or Run Time errors.


(a) arr[0];
//Result: 1
(b) arr[arr2.length-5];
//Result: 18
(c) s.charAt(arr.length);
//Result: o
(d) s.charAt(arr[3]);
//Run Time Error:StringIndexOutOfBoundsException: String index out of range: 18
(e) s.charAt(arr[5]);
//Run Time Error: ArrayIndexOutOfBoundsException: 5
(f) s.charAt(arr[1]);
//Result: 1
(g) arr3[arr.length];
//Result: [I@2a139a55
(h) arr3[arr.length][1];
//Result: 10
(i) arr3.length;
//Result: 5
(j) arr3[0].length;
//Result: 2
(k) arr3[1].length;
//Result: 2
(l) s.length();
//Result: 11
(m) s.charAt(s.indexOf('H'));
//Result: H
(n) s.charAt(s.indexOf('Q'));
//Run Time Error : StringIndexOutOfBoundsException: String index out of range: -1
(o) s.indexOf('Q');
//Result: -1
(p) arr2[0];
//Result: 0
(q) arr2=arr;
//Result: [I@15db9742
(r) arr[0] = arr3[2][0] + arr3[3][0];
//Result: 12
(s) arr[0] = (int)s.chatAt(6);
//Compile Time Error : cannot find symbol
//symbol: method chatAt(int)
(t) arr[0] = s.chatAt(6);
//Compile Time Error : cannot find symbol method chatAt(int)
(u) int j = 6.0;
//Compile Time Error: lossy conversion from double to int
(v) double d=7;
(w) s+='q';
(x) (s+"Goodbye!").length(;
(y) s==("Hello" + "World";
//Compile Time Error : Not a statement ==
(z) s.equals("Hello" + "World";

Please provide your comments or tumbs up.

Thanks