我试图创建一个程序来读取学生姓名和标记的输入,然后在表单GUI输出中给出该学生的姓名和成绩,但在编译时仍然存在问题。
import javax.swing.*;
public class p
{
private static String getGrade(int mark)
{
String grade;
if (mark<50)
grade="F";
else if (mark<65)
grade="P";
else if (mark<75)
grade="C";
else if (mark<85)
grade="D";
else
grade="HD";
return grade;
}
public static void main (String []args)
{
JOptionPane.showMessageDialog(null,"Welcome to the Mark Entry System");
String studentName = JOptionPane.showInputDialog(null,"Enter student name:");
int mark =Integer.parseInt(JOptionPane.showInputDialog(null,"Enter mark for student (out of 100)"));
String grade = getGrade(int mark);
JOptionPane.showMessageDialog(null,"The grade for " + studentName + " is " + grade);
}
}
答案 0 :(得分:1)
这里
String grade = getGrade(int mark); //Can't do this
传递一些int
String grade = getGrade(mark); //pass any integer you want