用swich语句编写JAVA程序,实现输入月份,显示季节?

急需答案!!!
2024年11月12日 04:22
有1个网友回答
网友(1):

import java.util.Scanner; public class test { public static void main (String args[]) { Scanner cs=new Scanner(System.in); System.out.println("请输入月份:"); int input=cs.nextInt(); String season; switch(input) { case 12: case 1: case 2: season="冬季"; break; case 3: case 4: case 5: season="春季"; break; case 6: case 7: case 8: season="夏季"; break; case 9: case 10: case 11: season="秋季"; break; default: season="无效"; } System.out.println(input+"月是"+season); } }