62,614
社区成员
发帖
与我相关
我的任务
分享
import javax.swing.JOptionPane;
public class DispalyWeek{
public static void main(String[] args){
String notice = "计算星期";
String message = "请输入当天是星期几,如:周一就输入1";
String message2 = "请输入天数,如:100";
String whatDayString = JOptionPane.showInputDialog(null, message, notice, JOptionPane.QUESTION_MESSAGE);
int whatDay = Integer.parseInt(whatDayString);
whatDay = whatDay <= 7 ? (whatDay > 0 ? whatDay : 7) : 7;
String numberOfDayString = JOptionPane.showInputDialog(null, message2, notice, JOptionPane.QUESTION_MESSAGE);
int numberOfDay = Integer.parseInt(numberOfDayString);
int newWhatDay;
if(numberOfDay <= 0){
newWhatDay = whatDay;
}else{
int temp = (whatDay + numberOfDay % 7) % 7;
newWhatDay = temp == 0 ? 7 : temp;
}
String output = "今天是星期" + whatDay +"', " + numberOfDay + "后是星期" + newWhatDay;
JOptionPane.showMessageDialog(null, output);
}
}