文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Java程序利用switch语句输出对应的月份的天数

Java程序利用switch语句输出对应的月份的天数

时间:2010-05-05  来源:小树

编写一个Java程序,接受用户输入的一个1――12之间的整数(如果输入的数据不满足这个条件,则要求用户重新输入),利用switch语句输出对应的月份的天数。

test.java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; 

public class test{
       public static void main(String[] args) throws IOException

       {
              System.out.println("请输入月份:");
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                   int i=Integer.parseInt(br.readLine());
                   while (i>12 || i<1){
                            System.out.println("请重新输入!");
                            br = new BufferedReader(new InputStreamReader(System.in));
                            a=Integer.parseInt(br.readLine());
                   }
                   System.in.close();
                   br.close();
                

                   switch (i){

                   case 1:
                       System.out.println("本月共 "+31+" 天");
                       break;

                   case 2:
                         System.out.println("本月共 "+28+"或"+29+" 天");
                       break;

                   case 3:
                           System.out.println("本月共 "+31+" 天");
                            break;

                   case 4:
                           System.out.println("本月共 "+30+" 天");
                           break;

                   case 5:
                            System.out.println("本月共 "+31+" 天");
                            break;

                   case 6:
                            System.out.println("本月共 "+30+" 天");
                            break;

                   case 7:
                            System.out.println("本月共 "+31+" 天");
                            break;

                   case 8:
                            System.out.println("本月共 "+31+" 天");
                            break;

                   case 9:
                            System.out.println("本月共 "+30+" 天");
                            break;

                   case 10:
                            System.out.println("本月共 "+31+"天");
                            break;

                   case 11:
                            System.out.println("本月共 "+30+" 天");
                            break;

                   case 12:
                            System.out.println("本月共 "+31+" 天");
                            break;

                   default:
                            System.out.println("请重新输入!");
                   }
            }
}

D:\java>javac test.java

D:\java>java test
请输入月份:

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载