NEWS: Total Picture Views: 147060 | Total Article Views: 155619 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. How to read a JSON and work with it | 3. PickUpThings with Becker Robot | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

Switch Statements Java

Description:

In this example I will be showing you how to use Switch Case

Code:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int choose = 0;

        System.out.print("Enter a number between 1 & 10:");
        choose = input.nextInt();

        switch(choose){
            case 1:
                System.out.println("You entered the number 1.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 2:
                System.out.println("You entered the number 2.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 3:
                System.out.println("You entered the number 3.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 4:
                System.out.println("You entered the number 4.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 5:
                System.out.println("You entered the number 5.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 6:
                System.out.println("You entered the number 6.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 7:
                System.out.println("You entered the number 7.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 8:
                System.out.println("You entered the number 8.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 9:
                System.out.println("You entered the number 9.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            case 10:
                System.out.println("You entered the number 10.");
                //Break is really important. If you don't put it, it will go to the next case.
                break;
            default:
                System.out.println("You did not enter a number between 1 & 10...");
        }
    }
}
Attachments:

Tags: Switch Switch Case Scanner

Total Views: 827

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 09/20/14


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.