Determine the output:class Evaluate { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 6; n = arr[arr[n] / 2]; System.out.println(arr[n] / 2); } }Select one:a.1b.6c.3d.0
Question
Determine the output:class Evaluate { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 6; n = arr[arr[n] / 2]; System.out.println(arr[n] / 2); } }Select one:a.1b.6c.3d.0
Solution
The output of the given Java program can be determined by following the steps of execution:
- An array
arris declared and initialized with the values from 0 to 9. - An integer
nis declared and initialized with the value 6. - The value of
nis updated toarr[arr[n] / 2]. Here,arr[n]isarr[6]which is 6. So,arr[6] / 2is3. Therefore,nis updated toarr[3]which is 3. - The value of
arr[n] / 2is printed. Here,arr[n]isarr[3]which is 3. So,arr[3] / 2is1.
Therefore, the output of the program is 1. So, the correct option is a. 1.
Similar Questions
Select the correct answer What will be the output of the following Java code?class evaluate { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 8; n = arr[arr[n] / 4]; System.out.println(arr[n] / 4); } }Options1230
Determine output:public class Test{ public static void main(String args[]){ int i; for(i = 1; i < 6; i++){ if(i > 3) continue ; } System.out.println(i); }}23466
Determine the output:public class A { public static void main(String argv[]){ int ary[]=new int[]{1,2,3}; System.out.println(ary[1]); }}Select one:a.2b.1c.Compilation Error:incorrect syntax
Find the output of the following code.class Output { public static void main(String args[]) { int arr[] = {11, 21, 31, 41, 51}; for ( int i = 1; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } }*11 21 31 4111 21 3121 3131 41 51
Determine the output:public class Test{ public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for(int i = 0; i < x.length; i++) System.out.print(y[i] + " "); }}Select one:a.1 2b.0 0c.0 0 0 0d.1 2 3 4
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.