-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