java输入月份--判断季节和天数 痛定思痛。 2022-06-04 01:44 290阅读 0赞 package test; import java.util.Scanner; import org.junit.Test; public class JTest \{ @Test public void test7() \{ int num = (int) (Math.random() \* 12 + 1); System.out.println("月份:"+num); switch (num) \{ case 3: case 4: case 5: System.out.println("春季"); break; case 6: case 7: case 8: System.out.println("夏季"); break; case 9: case 10: case 11: System.out.println("秋季"); break; case 12: case 1: case 2: System.out.println("冬季"); break; \} \} @Test public void test8()\{ System.out.print("输入月份:"); int month=new Scanner(System.in).nextInt(); switch(month)\{ case 1: case 3: case 5: case 7: case 8: case 10: case 12: System.out.println("此月的天数为:31"); break; case 4: case 6: case 9: case 11: System.out.println("此月的天数为:30"); break; case 2: System.out.println("此月的天数为:29"); break; default: System.out.println("输入月份(1-12)错误"); break; \} \} \}
还没有评论,来说两句吧...