Professional Documents
Culture Documents
Decisions: Decision Making in Java
Decisions: Decision Making in Java
Decisions
import java.util.Scanner;
continue
a !a
true false
false true
condition
evaluated
true
false
statement
true false
statement1 statement2
if(test==1)
{
//This block will be executed only if "test" is equal to 1
System.out.println("Hello");
}
else if(test==2)
{
//This block will be executed only if "test" is equal to 2
System.out.println("Hi");
}
else if(test==3)
{
//This block will be executed only if "test" is equal to 3
System.out.println("Good");
}
else
{
System.out.println("No Match Found");
}
} Copyright © 2016 Allan Ninyesiga Uganda Technology and Management University
Output
Hi
•See MinOfThree.java
import java.util.Scanner;
continue
• See GradeReport.java
import java.util.Scanner;
continue
switch (category)
{
case 10:
System.out.println ("a perfect score. Well done.");
break;
case 9:
System.out.println ("well above average. Excellent.");
break;
case 8:
System.out.println ("above average. Nice job.");
break;
case 7:
System.out.println ("average.");
break;
case 6:
System.out.println ("below average. You should see the");
System.out.println ("instructor to clarify the material "
+ "presented in class.");
break;
default:
System.out.println ("not passing.");
}
}
}
- If-statements
- If –else statements
- if-else ladder
- Nested if statements
- Switch statements