首页 > 其他 > 详细

javs switch 语句

时间:2019-12-25 12:49:51      阅读:129      评论:0      收藏:0      [点我收藏+]

 

//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 语句

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!