码迷,mamicode.com
首页 > 其他好文 > 详细

javs switch 语句

时间:2019-12-25 13:17:48      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:color   class   cas   main   ase   scan   sample   sys   语句   

 

//switch statement
import java.util.Scanner;
public class Sample {

    public static void main(String[] args) {
        int num;
        Scanner ip = new Scanner(System.in);
        System.out.print("Enter number between 1 to 4: ");
        num = ip.nextInt();
        switch (num) {
        case 1:
            System.out.println("Entered number is one");
            break;
        case 2:
            System.out.println("Entered number is two");
            break;
        case 3:
            System.out.println("Entered number is three");
            break;
        case 4:
            System.out.println("Entered number is four");
            break;
        default:
            System.out.println("invalid input");
        }
        ip.close();
    }
}



OUTPUT:
Enter number between 1 to 4: 3
Entered number is three

 

javs switch 语句

标签:color   class   cas   main   ase   scan   sample   sys   语句   

原文地址:https://www.cnblogs.com/sea-stream/p/12095992.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!