• Profile
  • Resume
  • Portfolio
  • Blog
Avatar

Nelson Silva

A human. Being. Coffee lover.

Blog

I Write My Thoughts Here

if, else if and else in Java

February 21, 2022 Java

In this post, you will learn how to work with decisions (if, else if and else) so that you can use that same knowledge and thus evolve.

package com.caffeinealgorithm.programminginjava;

public class IfElseIfAndElse {
  /*
    (if - if) condition is true {
      the code inside the if is executed
    }
    (else if - otherwise if) condition is true (else if only occurs if if condition is false) {
      code inside else if is executed
    }
    (else - if not) no condition (only occurs if condition of if and else if are false) {
      the code inside the else is executed
    }
  */

  public void Run() {
    int x = 30;

    if (x == 10)
      System.out.println("The value of x is equal to 10.");
    else if (x == 20)
      System.out.println("The value of x is equal to 20.");
    else
      System.out.println("The value of x is different from 10 and 20.");
  }
}

// The value of x is different from 10 and 20.

Don’t forget to watch the video and you can always read this post in Portuguese.

Happy coding!

Previous Next

Categories

  • Announcements
  • Python
  • C#
  • Java
  • Go

Latest Posts

  • for Loop in Go
    May 5, 2022
  • Switch in Go
    May 4, 2022
  • Comparison Operators in Go
    May 3, 2022
+351913416022
contact@nelsonsilvadev.com
Porto, Portugal
Nelson Silva © 2022 All Rights Reserved