Nested if Statement
1. Assume that int type variables
a and b have values a=2 and b=3.
Determine the outcome in each of the following peaces of code.
- if (a<b)
if (a==2)
System.out.println( "One");
else
System.out.println( "Two");
else
System.out.println( "Three");
System.out.println( "Four");
1. Solution
- if (a<b)
if (a==4)
System.out.println( "One");
else
System.out.println( "Two");
else
System.out.println( "Three");
System.out.println( "Four");
2.Solution
- if (a>b)
if (a==2)
System.out.println( "One");
else
System.out.println( "Two");
else
System.out.println( "Three");
System.out.println( "Four");
3. Solution
- if (a>b)
if (a==4)
System.out.println( "One");
else
System.out.println( "Two");
else
System.out.println( "Three");
System.out.println( "Four");
4. Solution