Decision Structures (1/30)
Flow of Control
Sequence
Branching/Selection
Boolean Expressions
Relational operators
Logical operators
Decision Structures
if
if-else
System.out.println("\n Course Grade: " + grade);
if (grade >= 60)
System.out.println("You have passed the course!");
else
System.out.println("You have failed the course.");Arrangement of identifiers, literals, and operators (relational and logical) that, when evaluated, results in either true or false.
AND
&&
OR
||
NOT
!
Java evaluates a logical expression from left to right, stopping as soon as the final truth value can be determined.
c = 3;
d =5;
e = 7;
f = 9;
c < = d || e == f
true || e == f
true/**
* Hayley Pappas
*
* RomanNumerals_V1.java
*
* Given a number (1-10), determine & display the corresponding Roman Numeral
*
* Input: A number (1-10)
*
* Processing: 1) Prompt user for a number (1-10)
* 2) Determine corresponding Roman Numeral
* 3) Display result
*
* Output: Corresponding Roman Numeral
*
* Note: Uses one way branching - if form
*/
// Import classes
import java.util.Scanner;
public class RomanNumerals_V1 {
public static void main(String[] args) {
// Variables
int number;
String romanNumeral = "";
// Scanner object for standard input
Scanner stdIn = new Scanner(System.in);
// Intro
System.out.println("\nRoman Numeral Converter ...");
// Prompt user for a number (1-10)
System.out.print("\nEnter a number (1-10): ");
number = stdIn.nextInt();
// Determine corresponding Roman Numeral
if (number == 1)
romanNumeral = "I";
if (number == 2)
romanNumeral = "II";
if (number == 3)
romanNumeral = "III";
if (number == 4)
romanNumeral = "IV";
if (number == 5)
romanNumeral = "V";
if (number == 6)
romanNumeral = "VI";
if (number == 7)
romanNumeral = "VII";
if (number == 8)
romanNumeral = "VIII";
if (number == 9)
romanNumeral = "IX";
if (number == 10)
romanNumeral = "X";
if (number < 1 || number > 10) // Input validation
romanNumeral = "";
// Display result
if (romanNumeral == "")
System.out.println("Error ... Invalid Number");
if (romanNumeral != "")
System.out.println("The corresponding Roman Numeral is " + romanNumeral);
}
}