我不确定是否需要在这里粘贴我的代码,但是当我去运行我的代码时,右键单击类对象,它通常表示运行为java应用程序,但现在它所说的只是运行配置。我无法运行java应用程序
我正在使用Eclise。
这是我的代码。我知道这是一个支架安置问题
import java.util.Calendar;
public class Date {
private int month;
private int day;
private int year;
public static void main(String[] args) {
}
public Date(int theMonth, int theDay, int theYear) {
month = checkMonth(theMonth);
year = checkYear(theYear);
day = checkDay(theDay);
System.out.printf("Date object constructor for date %s\n", toString());
}
private int checkYear(int testYear) {
if (testYear > 0)
return testYear;
else {
System.out.printf("Invalid year (%d) set to 1.\n", testYear);
return 1;
}
}
private int checkMonth(int testMonth) {
if (testMonth > 0 && testMonth <= 12)
return testMonth;
else {
System.out.printf("Invalid month (%d) set to 1.\n", testMonth);
return 1;
}
}
private int checkDay(int testDay) {
int daysPerMonth[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (testDay > 0 && testDay <= daysPerMonth[ month ])
return testDay;
if (month == 2 && testDay == 29 && (year % 400 == 0 ||
(year % 4 == 0 && year % 100 != 0)))
return testDay;
System.out.printf("Invalid day (%d) set to 1.\n", testDay);
return 1;
}
public void nextDay() {
int testDay = day + 1;
if (checkDay(testDay) == testDay)
day = testDay;
else {
day = 1;
nextMonth();
}
}
public void nextMonth() {
if (12 == month)
year++;
month = month % 12 + 1;
}
public String toString() {
return String.format("%d/%d/%d", month, day, year);
}
}
class DateTest {
public static void main(String args[]) {
System.out.println("Checking increment");
Date testDate = new Date(03, 13, 2011);
for (int counter = 0; counter < 3; counter++) {
testDate.nextDay();
System.out.printf("Incremented Date: %s\n", testDate.toString());
}
}
}
你的代码是否有'public static void main(String [] args)'? – 2011-03-13 18:40:50
不,我正在重新编排代码中的一些内容,并可能已将其删除。我是新来的Java,所以我不知道我删除了什么。你的声明在右上角?后面加括号吗?谢谢 – Mike 2011-03-13 18:44:05
注意:public static void main(String [] args){ } 这是一个空主。 – 2011-03-13 18:59:48