9 - Advanced Conditionals

Get an introduction to or review of advanced conditionals in Java programming.

Code HuntJava
1.0x

9 - Advanced Conditionals

Created 3 years ago

Duration 0:04:26
lesson view count 5
Get an introduction to or review of advanced conditionals in Java programming.
Select the file type you wish to download
Slide Content
Tags: Code Hunt Java
  1. Advanced Conditionals

    Slide 2 - Advanced Conditionals

  2. Sequential if statements

    Slide 3 - Sequential if statements

    • A series of if statements that occur sequentially are not connected to each other– each condition will be tested independently:
    • if (3 < 5) {
    • System.out.println("Yes");
    • }
    • if (10 >= 10) {
    • System.out.println("Good");
    • }
    • int y = 15;
    • if (y != 15) {
    • y--;
    • }
    • if (y > 0) {
    • y++;
    • }
    • System.out.println(y);
    • int x = 12;
    • if (x > 10) {
    • x /= 2;
    • }
    • if (x < 10) {
    • x++;
    • }
    • System.out.println(x);
  3. Chained if-else statements

    Slide 4 - Chained if-else statements

    • When there are more than two possible outcomes, we use chained if-else statements. Each condition will be tested only if all previous conditions were false:
    • if (4 < 3) {
    • System.out.println("1st");
    • } else if (10 < 12) {
    • System.out.println("2nd");
    • }
    • if (10 > 15) {
    • System.out.println("A");
    • } else if (20 < 19) { System.out.println("B");
    • }
    • int x = 12;
    • if (x == 3) {
    • System.out.println("Three");
    • } else if (x == 4) {
    • System.out.println("Four");
    • } else {
    • System.out.println("Other");
    • }
    • int y = 20;
    • if (y % 10 == 0) {
    • System.out.println("By 10");
    • } else if (y % 5 == 0) {
    • System.out.println("By 5");
    • } else if (y % 2 == 0) {
    • System.out.println("By 2");
    • }