偶是新手? 谁帮做几个题啊??

来源:百度知道 编辑:UC知道 时间:2024/06/06 09:08:56
1 编写一个JAVA程序 接受用户输入的一个1~12之间的整数(如果输入的数据不满足这个条件,则要求用户重新输入),利用switch语句输出对应月份的天数.
2 编写程序输出用户指定数据的所有素数因子.

谢谢了啊 !!!
都是 用JAVA 做啊 !~~~~~

import java.io.*;

class Months
{
public static void main(String[] args)
{
String month=null;
int n=0;
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

while(n<=0||n>=13)
{
System.out.println("请输入月份:1~12");
month=in.readLine();
try
{
n=Integer.parseInt(month);
}catch(NumberFormatException ne)
{
n=0;
}
}
}catch(IOException e)
{
e.printStackTrace();
}
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println(n+"月有"+31+"天");
break;
case 4:
case 6:
case 9:
case 11:
System.out.println(n+"月有"+30+"天");
break;
case 2:
System.out.println(n+"月有"+28+"天(闰年29天)");
break;
}
}