-4
我不能讓這些編譯它似乎是我試圖傳遞布爾值的地方。第一個有2個錯誤,沒有任何意義,我Java傳遞布爾值
public class Date {
public int m;
public int d;
public int y;
boolean isLeapYear;
public String monthIs(){
return month;
m = Integer.parseInt(month);
}
public String dayIs(){
return day;
d = Integer.parseInt(day);
}
public Date(String year){
y = Integer.parseInt(year);
// Is y Divisible by 4
if (y % 4 == 0){
// Is y Divisible by 4 but not 100
if (y % 100 != 0)
isLeapYear = true;
// Is y Divisible by 4 and 100 and 400
else if (y % 400 == 0)
isLeapYear = true;
// It's Divisible by 4 and 100 but not 400
else
isLeapYear = false;
}
// It's not divisible by 4
else
{
isLeapYear = false;
public boolean getisLeapYear()
{
return isLeapYear;
}
}
}
}
DateJDialog類:
import javax.swing.JOptionPane;
/** This program runs the Date class to determine if
* the date entered falls within a leap year.
*/
public class DateJDialog
{
public static void main(String[] args)
{
String month;
String day;
String year;
boolean isitLeapYear;
Date date;
//Get Input
JOptionPane.showMessageDialog(null, "This program determines if the date
entered falls within a leap year.");
month = JOptionPane.showInputDialog("What month?");
day = JOptionPane.showInputDialog("What day?");
year = JOptionPane.showInputDialog("What year?");
//Create Date object
date = new Date(year);
if (date.getisLeapYear()==true);
if (isLeapYear = true)
JOptionPane.showMessageDialog(null, month + "-" + day + "-" + year
+ " does fall within a leap year.");
else
JOptionPane.showMessageDialog(null, month + "-" + day + "-" + year
+ " does not fall within a leap year.");
System.exit(0);
}
}
第1步:將您的代碼格式化爲人類可讀的。第2步:查看錯誤消息。發生錯誤時不要放棄。 *閱讀錯誤*嘗試解決它。 – David 2014-12-01 20:11:36
你不能在另一種方法的中間定義一個方法('getIsLeapYear')。 – ajb 2014-12-01 20:11:46
你需要做'isLeapYear == true'而不是'isLeapYear = true'-另外,總是發佈你得到的錯誤 - 不要讓我們猜測你在屏幕上看到的是什麼。 – nos 2014-12-01 20:11:58