我正在使用以下代码来生成对象的文本转储:
public static String generateText(Quiz quiz){
String endResult = "";
for (QuizQuestion question : quiz.getQuestions()) {
endResult += question.getQuestion();
endResult += System.lineSeparator();
endResult += question.getAnswer1();
endResult += System.lineSeparator();
endResult += question.getAnswer2();
endResult += System.lineSeparator();
endResult += question.getAnswer3();
endResult += System.lineSeparator();
endResult += question.getAnswer4();
endResult += System.lineSeparator();
endResult += question.getCorrectAnswer();
endResult += System.lineSeparator();
}
return endResult;
}
但是,当我将endResult
打印到文件tis时,输出是:
questiona1a2a3a4a
然后它打印4空行。如何解决?