在我的Tafe工作中,我必须设置它,以便我的Java程序询问用户他们的名字和他们的成绩点平均值,然后将所述平均值乘以10,并显示结果。目前我的代码看起来像这样
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String Name;
String gradePoint;
Name=JOptionPane.showInputDialog(null, "Please enter your name.", "Input Name", JOptionPane.QUESTION_MESSAGE);
gradePoint = JOptionPane.showInputDialog(null, "What is your grade point average?", "Grade point average", JOptionPane.QUESTION_MESSAGE);
System.out.println("Your name is " + Name + ", and your grade point average is " + gradePoint + ", so your book store credit is " + Integer.parseInt(gradePoint)*10);
}
我认为这在公理上是错误的,但我仍然是Java的新手。请告诉我必须做出的任何和所有改变。
答案 0 :(得分:0)
我采用了你的代码并制作了一个仅使用对话框的工作版本。扫描仪输入上没有System.out。从您的评论中,您似乎正在使用JavaFX项目。这不是JavaFX代码,只是常规应用程序......
public static void main(String[] args) throws Exception {
String name = JOptionPane.showInputDialog(null,
"Please enter your name.", "Input Name", JOptionPane.QUESTION_MESSAGE);
String gradePointString = JOptionPane.showInputDialog(null,
"What is your grade point average?", "Grade point average", JOptionPane.QUESTION_MESSAGE);
int gradePoint = Integer.parseInt(gradePointString);
int x = 10;
JOptionPane.showConfirmDialog(null,
"Your name is " + name + ", and your grade point average is " + gradePoint +
", so your book store credit is " + (gradePoint*x));
}