// Alex Deines
import javax.swing.*;
public class DeinesAdmissions
{
public static void main(String[] args)
{
String anwserString;
double anwser;
double y;
anwserString= JOptionPane.showInputDialog(null,"Enter your GPA", "GPA", JOptionPane.QUESTION_MESSAGE);
anwser = Double.parseDouble(anwserString);
JOptionPane.showInputDialog(null,"Enter your Admission Test Score", "Test Score", JOptionPane.QUESTION_MESSAGE);
y = Integer.parseInt(anwserString);
if(anwser>=3 && y>=60 || anwser>=0 && y>=85 )
JOptionPane.showMessageDialog(null, "You have been accepted");
else
JOptionPane.showMessageDialog(null, "Sorry we must reject your application");
}
}
异常(exception):
Exception in thread "main" java.lang.NumberFormatException: For input string: "3.2"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at DeinesAdmissions.main(DeinesAdmissions.java:16)
插入变量后,我收到此错误代码。有人能引导我走向正确的方向吗?
最佳答案
y
是 double
所以使用 Double.parseDouble :(与anwser
相同)
y = Double.parseDouble(anwserString);
您可以使用 Double.compare 比较 double
Compares the two specified double values. The sign of the integer value returned is the same as that of the integer that would be returned by the call:
new Double(d1).compareTo(new Double(d2))
注意拼写错误 anwser
应拼写为 answer
,作者:@Katamari
您忘记在 @JohnnyMopp 的第二次调用中更新 anwserString
anwserString = JOptionPane.showInputDialog(null,"Enter your Admission Test Score", "Test Score", JOptionPane.QUESTION_MESSAGE);
关于java - 线程中出现异常,java代码将无法正常执行。 if/else 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53764525/