我是新手,这是我第一次尝试输入char。我写了以下程序来输入成绩和显示结果: import java.util.Scanner; 公共等级
{
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
do
{
System.out.println("Enter grade(A/B/C/D/E/F): ");
char grade = obj.next(".").charAt(0);
switch(grade)
{
case "A": //The error is displayed here in "A"
System.out.println("Excellent");
break;
case "B": case "C":
System.out.println("Well done");
break;
case "D": case "E":
System.out.println("You passed");
break;
case "F":
System.out.println("Better try");
break;
default:
System.out.println("Invalid");
break;
}
System.out.println("Do you want to continue? (y/n): ");
char cont = obj.nextChar();
}
while (cont == y);
}
}
当我编译它时,它突出显示“A”并说java.lang.String不能转换为char。我该怎么办?