十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
你好,按照你的要求代码如下,给出了注释,可以直接运行
创新互联公司网站建设提供从项目策划、软件开发,软件安全维护、网站优化(SEO)、网站分析、效果评估等整套的建站服务,主营业务为网站制作、做网站,成都APP应用开发以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。创新互联公司深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
public class Example10_3 {
public static void main(String args[]) {
// 从1月打到12月
for (int i = 1; i = 12; i++) {
System.out.println(getSeason(i));
}
}
// 根据月份获得季节
private static String getSeason(int month) {
switch ((month - 1) / 3) {
case 0:
return "春";
case 1:
return "夏";
case 2:
return "秋";
case 3:
return "冬";
default:
return "错误";
}
}
}
public String getMonthName() {
int month = (int) (Math.random() * 12 + 1);
switch (month) {
case 1:
return "一月";
case 2:
return "二月";
case 3:
return "三月";
case 4:
return "四月";
case 5:
return "五月";
case 6:
return "六月";
case 7:
return "七月";
case 8:
return "八月";
case 9:
return "九月";
case 10:
return "十月";
case 11:
return "十一月";
default:
return "十二月";
}
}
PS: 是不是作业,上学要好好上呀,不能老指望别人,你学软件学费挺贵的吧!
import java.util.Scanner;
public class QuestionOne {
private static boolean start;
public static void main(String[] args) {
boolean really=true;
Scanner sc=new Scanner(System.in);
while(really=true){
boolean temp=true;
int num=0;
start:
while(temp==true){
System.out.print("请输入要查询的月份:");
num=sc.nextInt();
if(num12 ||num1){
System.out.println("你输入的月份错误,请重新输入");
continue;
}
temp=false;
}
int dayOfMonth = 0;
switch (num) {
case 1:
dayOfMonth=31;
break;
case 2:
dayOfMonth=28;
break;
case 3:
dayOfMonth=31;
break;
case 4:
dayOfMonth=30;
break;
case 5:
dayOfMonth=31;
break;
case 6:
dayOfMonth=30;
break;
case 7:
dayOfMonth=31;
break;
case 8:
dayOfMonth=31;
break;
case 9:
dayOfMonth=30;
break;
case 10:
dayOfMonth=31;
break;
case 11:
dayOfMonth=30;
break;
case 12:
dayOfMonth=31;
break;
default:
break;
}
if(num==2){
System.out.println("'"+num+"'月对应的天数是:'"+dayOfMonth+"'或者29");
}
else{
System.out.println("'"+num+"'月对应的天数是:'"+dayOfMonth+"'");
}
System.out.println("C为继续,其余任意键退出!");
String t=sc.next();
if(t!="c"){
really=false;
}
}
}
}//(楼主如果需要判断闰年的话给发个悄悄话,这是为2月准备的)
public class myFasd extends Frame implements ActionListener {
Label res;
TextField my;
String word[] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
public myFasd() {
my = new TextField(20);
res = new Label("month", Label.LEFT);
setLayout(new GridLayout(6, 1));
add(my);
add(res);
my.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String s = my.getText();
int n = Integer.parseInt(s);
if (n 1 || n 12) {
res.setText("input error.");
} else {
res.setText(word[n - 1]);
}
}
public static void main(String args[]) {
Frame my = new myFasd();
my.setSize(300, 300);
my.setVisible(true);
}
}
帮你改了一下,希望对你有所帮助。