5 years ago in Java Arrays

What is the output of this program?

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);

}
}

[A] 3
[B] 0
[C] 6
[D] 1
Loading...
Next Question

Overall Stats

Attempted 336
Correct 95
Incorrect 86
Viewed 155

Answers

Guest
Guest
DESIKAN AK - 3 years ago

output : Value of n=3 ; Value of arr[n]=3 ; Value of arr[n]/2 =1

DESIKAN AK - 3 years ago

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("Value of n=" + n); System.out.println("Value of arr[n]="+ arr[n]); System.out.println("Value of arr[n]/2 ="+arr[n]/2); }

DESIKAN AK - 3 years ago

Executed output for this program

Shamsa hafeez
Shamsa hafeez - 1 week ago

Shamsa hafeez from Lahore, Pakistan is saying 6 is correct answer

Rakhi Sharma
Rakhi Sharma - 2 weeks ago

Rakhi Sharma is saying 0 is correct answer

Related Questions