Java Programming Tutorial – 12 – Switch Statement

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






23 responses to “Java Programming Tutorial – 12 – Switch Statement”

  1. ThatGuy1797 Avatar

    Added my own little touches to this code by making the case take in user input from the keyboard. Your tutorials are very helpful, I'm learning Java from C++ for my new transfer college. You're a life saver, man!

  2. Tarun Chand Avatar

    cant we give the case a range in java like we do i c++? like:
    case 1 .. 10:
    do something;

  3. Earl John Calizar Avatar

    hi may i ask how do i input again if the user is not writing the correct answer like this code.

    import java.util.*;
    class aaa
    public static void main(String args[])
    Scanner s = new Scanner(;
    System.out.print("Enter age 1-3:t");
    int age = s.nextInt();
    switch (age)
    case 1:
    System.out.print("your age is one");
    case 2:
    System.out.print("your age is two");
    case 3:
    System.out.print("your age is three");


  4. Ashray Aman Avatar

    Is it necessary to put a default statement? If i had already provided with case 3: and i know that the program's not going to crash. But do I need to put it always?

  5. Ly Ralei Avatar

    I'm happy that I started in C++. Tried to learn lots in it and then here I am, java coding is like c++ that's why it takes me just 1 view on video to learn it.

  6. Uğur Can Aydın Avatar

    When i finish a tutorial video, i say "Let's watch another one." You express things pretty well in a short period of time. I wish you were my teacher.I would attend to ur all classes.

  7. Viraj Murab Avatar

    nice explanation and really fast type writing

  8. Xydez Avatar

    Instead of writing "System.out.println" you can just write "sysout" and press CTRL + Space.

  9. Jon Schwartz Avatar

    disliked because you spelled 'trouble' wrong

  10. bengtig77 Avatar

    this guy doesn't know to use the shortcut key for system println..just type syso ctrl space !

  11. Michael Darby Avatar

    These are GREAT tutorials, but after watching them for a few hours in the middle of the night it gets kind of… boring.

  12. Munirul Azam Avatar

    How can I add a condition in a switch statement? like we add conditions in if else statements. for example, if variable>0 then do this. how do I do that with a switch statement?

  13. Mihai Muntean Avatar

    Just a little bit of what I've learned from you! Thank you very much and cya you later. Btw, you rock!

    import java.util.Scanner;

    public class main {
    public static void main(String args[]) {
    int numar1, numar2, rezultat;
    rezultat = 0;
    Scanner imput = new Scanner(;
    System.out.print("Introduceti primul numar: ");
    numar1 = imput.nextInt();

    System.out.print("Introduceti al doilea numar: ");
    numar2 = imput.nextInt();

    System.out.print("Introduceti semnul ecuatiei preferate: ");

    switch ( {
    case "+":
    if (numar1 == 5) {
    rezultat = numar1 + numar2;
    "This is a simple IF inside a switch command. Good Job! Oh yea, the answer is: " + rezultat);
    } else {
    rezultat = numar1 + numar2;
    System.out.println("Rezultatul ecuatiei este: " + rezultat);
    case "-":
    rezultat = numar1 – numar2;
    System.out.println("Rezultatul ecuatiei este: " + rezultat);
    case "*":
    rezultat = numar1 * numar2;
    System.out.println("Rezultatul ecuatiei este: " + rezultat);
    case "/":
    rezultat = numar1 / numar2;
    System.out.println("Rezultatul ecuatiei este: " + rezultat);
    System.out.println("Ecuatii disponibile: + , – , * , / ");


  14. Nikola Stevanovic Avatar

    Is it possible to that with string?

    for example, like a traffic light, because mine wont work

    public static void main(String[] args) {

    String light;

    light = red;

    switch (light) {

    case red:

    case yellow:
    System.out.println("Get ready");

    case green:

    System.out.println("Traffic light don't work");




  15. Frias Kris Avatar

    Nice, you're really cool when you explaining the program 🙂 HAHAHAHHAHA

  16. Srijan Poudel Avatar

    String age;
      System.out.println("Tell me your age?");
      Scanner Srij = new Scanner(;
      age = Srij.nextLine();
     ###    switch (age){
      case "ONE":
      case "TWO":
       System.out.print("You can talk");
      case "THREE":
       System.out.println("You ca be in trouble");
       System.out.println("I dont how old you are");
       break;PLz tell me the mistake at Switch line. It says    Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted at apples.apples.main(

  17. Pratic Bhatta Avatar

    can't we use it with multiple variable ??? please reply

  18. Programming Tutorials In Telugu Avatar

    Can we use condition in Switch case like

    case i>85 : System.out.println("A grade");
    case i>65 : System.out.println("b grade");
    case i>55 : System.out.println("c grade");
    case i>36: System.out.println("d grade");
    default : System.out.println("fail");


  19. ThePainkiller1982 Avatar

    how can we use operands like < or > in switch statements?

  20. shizyninjarocks Avatar

    Well spelled kind sir, well speled.

  21. Hurricane Lambda Avatar

    Now two year olds can talk. You're one heck of a dude, man (I mean, thanks for the video, I understand it now 🙂 :))

  22. C. A. Avatar

    I like how you say just deal with it with the spelling errors.

Leave a Reply

Your email address will not be published. Required fields are marked *