UI.java
import java.util.Scannerpublic class UI {
static Scanner sc=new Scanner(System.in)
public static int askInt(String s){
System.out.print(s)
return sc.nextInt()
}
public static void println(String s){
System.out.println(s)
}
}
EE.java
public class EE {public void validateDateCore(){
int year =UI.askInt("Enter the year: ")
int month=UI.askInt("Enter the month: ")
int day=UI.askInt("Enter the day: ")
if(year < 1){
UI.println("The year is not a valid number.")
return
}
if(month<1 || month>12){
UI.println("The month is not a valid number.")
return
}
int monthDay=0
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:monthDay=31break
case 4:
case 6:
case 9:
case 11:monthDay=30break
case 2:
if((year%4==0 && year%100!=0) || year%400==0){
monthDay=29
}else{
monthDay=28
}
break
}
if(day<1 || day>monthDay){
UI.println("The day is not a valid number.")
return
}else{
UI.println("It is "+day+"/"+month+"/"+year+".")
}
}
public static void main(String[] args) {
new EE().validateDateCore()
}
}
运行结果
修改部分见注释
public static void main(String[] args){
System.out.println(" 日 一 二 三 四 五 六")
Calendar rili = Calendar.getInstance()
rili.set(2011, 3, 1)
int xingqi = rili.get(Calendar.DAY_OF_WEEK) - 1
String a[] = new String[xingqi + 30]
for (int i = 0 i < xingqi i++)
{
a[i] = "**"
}
for (int i = xingqi, n = 1 i < xingqi + 30 i++)
{
if (n <= 9)
a[i] = String.valueOf(n) + " "
else
a[i] = String.valueOf(n)
n++
}
//a[i]的i从0开始,你下面从1开始循,自然少了第一个
for (int i = 0 i < a.length i++)
{
//遇到星期六应该是先打印日期,再换行,你之前是先换行,再打星期六
System.out.print(" " + a[i])
//改了循环起始位置,此处改为i+1
if ((i + 1)% 7 == 0)
{
System.out.println(" ")
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)