欢迎光临散文网 会员登陆 & 注册

Java练习

2022-11-02 18:39 作者:沐笙--ms  | 我要投稿


编写一个计算某个月份天数的程序,根据用户输入的月份,判断并输出该月份包含的天数。

package yue;


import java.util.Scanner;


public class yue {


public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("请输入一个月份:");  //输入月份

 int month = input.nextInt();

 if(month==2)

 {

 System.out.println(month+"月闰年是29天,不是闰年则是28天");

 }

 else if(month==4||month==6||month==9||month==11)

 {

 System.out.println(month+"月是30天");

 }

     else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)

     {

      System.out.println(month+"月是31天");

     } 

}

}


Java练习的评论 (共 条)

分享到微博请遵守国家法律