Java
TOPIC 15 – IF STATEMENTS – PART 2

AP EXTRA

 

AP LESSON WORK

 

 

QUESTION 1

What will be outputted by the following?

 

a)

 

Scanner scr = new Scanner(System.in);

System.out.println("Enter a number");

int num = scr.nextInt();

System.out.println(num + " is an " + ((num % 2 == 0) ? "even" : "odd") + " number.");

 

<more to come>

 

 

 

 

QUESTION 2 – NESTED ? OPERATORS

 

What will the following do?  You can assume that a, b and c have been initialized.

 

     int m = (a > b) ? ((a > c) ? a : c) : ((b > c)? b : c);