Java程序 switch语句
生活随笔
收集整理的這篇文章主要介紹了
Java程序 switch语句
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
switch語句
import java.util.Scanner; public class Switchr {public static void main(String args[]){int a;System.out.println("請輸入0到6的數(shù):");Scanner scanner=new Scanner(System.in);a=scanner.nextInt();if (a<0||a>7){System.out.println("輸入錯誤!!");System.exit(-1);}switch(a) {case 0:System.out.println("今天是星期一!");break; case 1: System.out.println("今天是星期二!");break;case 2:System.out.println("今天是星期三!");break; case 3:System.out.println("今天是星期四!");break;case 4:System.out.println("今天是星期五!");break; case 5:System.out.println("今天是星期六!");break; case 6:System.out.println("今天是星期天!");break;}}}執(zhí)行結(jié)果
總結(jié)
以上是生活随笔為你收集整理的Java程序 switch语句的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: GeneXus for SAP的最新动态
- 下一篇: java美元兑换,(Java实现) 美元