
JAVA!急!为什么我编好的这个类为什么始终没有运行程序,只有运行配置,大家帮我看看是不是代码没有写对
JAVA!急!我是初学者,为什么我编好的这个类为什么始终没有运行程序,只有运行配置,大家帮我看看是不是代码没有写对呀,我都要快疯了,请大家一定发要帮帮我,实在感谢。代码如...
JAVA!急!我是初学者,为什么我编好的这个类为什么始终没有运行程序,只有运行配置,大家帮我看看是不是代码没有写对呀,我都要快疯了,请大家一定发要帮帮我,实在感谢。
代码如下:
这样写,mian方法也没有!!
这样写,面方法也没有
这个是main方法,始终都没有运行程序,是不是我代码哪里写错了呢?
import javax.swing.JOptionPane;
public class GetLeapYear {
public int year;
public void run() {
this.inputYear();
boolean flag = this.intLeapYear(year);
if (flag = true) {
JOptionPane.showMessageDialog(null, year + "年是闰年");
} else {
JOptionPane.showMessageDialog(null, year + "年不是闰年");
}
}
// 判断闰年
public boolean intLeapYear(int year) {
if (year % 400 == 0) {
return true;
} else if (year % 4 == 0 && year % 100 != 0) {
return true;
}
return false;
}
// 输入年,并判断输入错误!
public int inputYear() {
String str = JOptionPane.showInputDialog(null, "请输入你要求的年份:");
if (!str.matches("^-?[1-9][0-9]*$")) {
JOptionPane.showMessageDialog(null, "你输入的数不是整数,请重新输入");
return inputYear();
} else {
int year = Integer.parseInt(str);
if (range(year)) {
JOptionPane.showMessageDialog(null, "你输入的年份超过判断范围,请重新输入");
return inputYear();
}
return year;
}
}
// 规定输入年的范围
public boolean range(int year) {
return year > 9999 || year < -10000;
}
}
---------------------------------------------------- 展开
代码如下:
这样写,mian方法也没有!!
这样写,面方法也没有
这个是main方法,始终都没有运行程序,是不是我代码哪里写错了呢?
import javax.swing.JOptionPane;
public class GetLeapYear {
public int year;
public void run() {
this.inputYear();
boolean flag = this.intLeapYear(year);
if (flag = true) {
JOptionPane.showMessageDialog(null, year + "年是闰年");
} else {
JOptionPane.showMessageDialog(null, year + "年不是闰年");
}
}
// 判断闰年
public boolean intLeapYear(int year) {
if (year % 400 == 0) {
return true;
} else if (year % 4 == 0 && year % 100 != 0) {
return true;
}
return false;
}
// 输入年,并判断输入错误!
public int inputYear() {
String str = JOptionPane.showInputDialog(null, "请输入你要求的年份:");
if (!str.matches("^-?[1-9][0-9]*$")) {
JOptionPane.showMessageDialog(null, "你输入的数不是整数,请重新输入");
return inputYear();
} else {
int year = Integer.parseInt(str);
if (range(year)) {
JOptionPane.showMessageDialog(null, "你输入的年份超过判断范围,请重新输入");
return inputYear();
}
return year;
}
}
// 规定输入年的范围
public boolean range(int year) {
return year > 9999 || year < -10000;
}
}
---------------------------------------------------- 展开
1个回答
展开全部
debug断点打到每个方法上进行调试,看看原因,以后这个是经常做的事情,原因还是自己找找比较好;main方法那个类右键debug
追问
我能自己找,我还来着你们问你们吗~~~
追答
你右键run了报什么错误呢
public static void main(String[] args) {
JOptionPane.showInputDialog("");
}
这个是能够出来的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |