Hey Parag,
Lets put it in more simple way:
public int guessWhat( int arr[] )
{ int x= 0;
for( int i = 0; i < arr.length; i++ )
x = x < arr[i] ? arr[i] : x; // A
return x;
}
Code at A: Lets take a example
Say arr[]={1,2,3,4}
It means array has 4 elements and array length is 4.
Now lets go through for loop
first iteration
for( int i = 0; i < arr.length; i++ )
x = x < arr[i] ? arr[i] : x; // A
return x;
//x=x<arr[0]?arr[0]:x;>
Going from left to right x is assigned to x whihc is equivalent to arr[i] if arr[i] is greater than x and if not then it is equivalent to x itself.
In this case arr[0] is 1 whihc is greater than original value of x which iz zero so x is 1
In second loop x is 1 but the arr[1] is 2 whihc is greater
in third loop x is 2 but arr[2] is 3 whihc is greater
in fourth loop x is 3 but arr[3] is 4 whihc is greater and therfore x becomes 4 whihc is ultimately returned.
I hope this makes it clear.