我正在編寫一個非常簡單的類的程序。所有它需要我打印成績表,並能夠輸入3條信息(這裏用字符串studentName, idNumber
和assignmentTitle
表示)。成績表必須存儲在一個字符串中。好吧,這對我來說看起來好像它應該工作,但無論出於什麼原因,輸出studentName, idNumber
和assignmentTitle
應該出現在空值輸出。非常簡單的問題,我敢肯定,有什麼想法?這是我的代碼。String返回空值的Java問題,儘管使用Scanner類輸入數據
import java.util.Scanner;
class GradingForm
{
static String studentName;
static String idNumber;
static String assignmentTitle;
static String gradeSheet = "********************************* \n\n" +
assignmentTitle + "\n\n" +
studentName + " " + idNumber + "\n\n" +
"Grade Summary:\n\n" +
"Program Correctness: Quality of Style:\n" +
"Late Deduction: Overall Score:\n" +
"Comments:";
public static void gradeFormValues()
{
Scanner inData;
inData = new Scanner(System.in);
System.out.println("Enter student's name: ");
studentName = inData.nextLine();
System.out.println("Enter student ID number: ");
idNumber = inData.nextLine();
System.out.println("Enter Assignment title: ");
assignmentTitle = inData.nextLine();
}
public static void printGradeSheet()
{
System.out.println(gradeSheet);
}
public static void main(String[] args)
{
gradeFormValues();
printGradeSheet();
}
}
謝謝....計算它會很簡單 – Marq