我需要幫助完成作業。我需要編寫課程程序,將成績轉換成成績。如果等級與A +一樣,則將等級點增加0.3,並且 - 將減少0.3。需要作業想法
private static final double GradePoint = 0;
private static Scanner input;
public static void main(String [] args)
{
String grade ;
double GradePoint = 0;
System.out.print("Please enter your grade: ");
input = new Scanner(System.in);
grade = input.nextLine();
switch(grade)
{
case "A":
case "a": GradePoint = 4; break;
case "B":
case "b": GradePoint = 3; break;
case "C":
case "c": GradePoint = 2; break;
case "D":
case "d": GradePoint = 1; break;
case "F":
case "f": GradePoint = 0; break;
}
System.out.print("Your grade is: "+GradePoint);
}
public double getGradePoint(String grade)
{
return GradePoint;
}
我不明白的是如何使用該方法來計算。我仍然是初學者。
你的問題是什麼? –
@Mohd Khairul:只需檢查第二個字母。你有方法將字符串轉換爲數組。並檢查第二個字符匹配+或 - 不是你想要什麼? –
作業標籤?另外,要搜索「+」,您可以使用這種名爲indexOf的方法。例如:if(str1.indexOf(「#」)> -1){//#在str1中找到}。 –