• Profile
  • Resume
  • Portfolio
  • Blog
Avatar

Nelson Silva

A human. Being. Coffee lover.

Blog

I Write My Thoughts Here

Switch in Java

February 24, 2022 Java

In this post, you will learn how to work with switch so that you can use that same knowledge and thus evolve.

  • the switch is another way of working with decisions and can only check an equality relationship, ie it cannot use comparison operators;
  • the case compares what was defined in itself with the content of the argument that was defined in the switch;
  • the default is executed when the content of the argument that was defined in the switch is not found in any case.
package com.caffeinealgorithm.programminginjava;

public class Switch {
  public void Run() {
    char _case = 'D';

    switch (_case) {
      case 'A':
        System.out.println("The case A exists.");
        break;
      case 'B':
        System.out.println("The case B exists.");
        break;
      case 'C':
        System.out.println("The case C exists.");
        break;
      default:
        System.out.printf("The case %c does not exist.", _case);
        break;
    }
  }
}

// The case D does not exist.

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