编写JAVA程序 接受用户输入1-12之间的整数 若不符合条件则重新输入 利用switch语句输出对应月份的天数 5
1个回答
展开全部
import java.util.*;
public class Demo {
public void fun(){
Scanner sc = new Scanner(System.in);
try {
int data= sc.nextInt();
switch(data){
case 1: System.out.println("31 days");break;
case 2: System.out.println("28 days");break;
case 3: System.out.println("31 days");break;
case 4: System.out.println("30 days");break;
case 5: System.out.println("31 days");break;
case 6: System.out.println("30 days");break;
case 7: System.out.println("31 days");break;
case 8: System.out.println("31 days");break;
case 9: System.out.println("30 days");break;
case 10: System.out.println("31 days");break;
case 11: System.out.println("30 days");break;
case 12: System.out.println("31 days");break;
default:fun();
}
} catch(Exception e) {
System.out.println("bad input!");
}
}
public static void main(String args[]){
Demo demo=new Demo();
demo.fun();
}
}
public class Demo {
public void fun(){
Scanner sc = new Scanner(System.in);
try {
int data= sc.nextInt();
switch(data){
case 1: System.out.println("31 days");break;
case 2: System.out.println("28 days");break;
case 3: System.out.println("31 days");break;
case 4: System.out.println("30 days");break;
case 5: System.out.println("31 days");break;
case 6: System.out.println("30 days");break;
case 7: System.out.println("31 days");break;
case 8: System.out.println("31 days");break;
case 9: System.out.println("30 days");break;
case 10: System.out.println("31 days");break;
case 11: System.out.println("30 days");break;
case 12: System.out.println("31 days");break;
default:fun();
}
} catch(Exception e) {
System.out.println("bad input!");
}
}
public static void main(String args[]){
Demo demo=new Demo();
demo.fun();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询