import java.util.Scanner;
public class LeapYearTester{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Please enter a year");
int year_input = input.nextInt();
// now make a Year object
Year theYear = new Year(year_input);
// now check to see if it's a leap year
if (theYear.isLeapYear())
System.out.println("That's a leap year!");
else
System.out.println("That's not a leap year!");
}
}
public class Year
{
// declare your instance variables here
private int theYear;
private int Year;
// write your constructor here
public Year(int y)
{
y=Year;
}
static boolean isLeapYear(final int Year) {
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0);
//(((Year%4==0) || (Year%400)) && ((!Year%100==0) || (Year%400=0)))
}
}
以上是Main,不能更改。遇到課堂上的麻煩。使用方法的閏年計算
「有帶班的麻煩。」什麼樣的麻煩,與哪一類? –
你有我的同情心。現在你的問題是什麼? –
爲什麼你班上有兩個「int」字段?它也看起來像你的構造函數不初始化它們中的任何一個。 – 4castle