Question: First of all, apologies for the following question, i am new to java, i have taken the example from a book but it fails to completely explain itself.

I have been reading about the ? operator and how it functions and using the below as an example to learn from:

```
class Ternary {
    public static void main(String args[]) {
        int i, k;
        i = 10;
        k = i < 0 ? -i : i; // get absolute value of i
        System.out.print("Absolute value of ");
        System.out.println(i + " is " + k);

        i = -10
        k = i < 0 ? -i : i; //get absolute value of i
        System.out.print("Absolute value of ");
        System.out.println(i + " is " + k);
    }
}

```

I understand how the first part gives the result of 10.
But i cannot follow how the second part gives the result of 10?

Apologies if this is plainly obvious.

Answer: 
The conditional operator is used to decide which of two values to assign to a variable.

It takes the form:

type variableName = (boolean condition) ? valueIfTrue : valueIfFalse;

In your case you have:

```
public static void main(String[] args){
    int i, k;
    i = -10;
    k = i < 0 ? -i : i; //get absolute value of i
    System.out.print("Absolute value of ");
    System.out.println(i + " is " + k);
}

```

So, we are saying:

i < 0, well i is equal to -10 and is therefore less than 0. therefore the true condition is assigned, which has the value of -i.

Since -(-10) = -\*-10 = 10 [i.e minus times minus is plus], the output is 10.
when setting k, we have the condition

```
i < 0

```

followed by the ?, which asks "Is i less than 0. If it is, it will return the first result (-i), and if it is not it will return the second result (i).

It means the same thing as:

```
if (i < 0){
    k = -i;
else{
    k = i;
}

```