Knowee
Questions
Features
Study Tools

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

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given Java program can be determined by following the steps of execution:

  1. An array arr is declared and initialized with the values from 0 to 9.
  2. An integer n is declared and initialized with the value 6.
  3. The value of n is updated to arr[arr[n] / 2]. Here, arr[n] is arr[6] which is 6. So, arr[6] / 2 is 3. Therefore, n is updated to arr[3] which is 3.
  4. The value of arr[n] / 2 is printed. Here, arr[n] is arr[3] which is 3. So, arr[3] / 2 is 1.

Therefore, the output of the program is 1. So, the correct option is a. 1.

This problem has been solved

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

1/3

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.