我添加了System.err.flush();和System.out.flush();但是问题仍然存在。看来这些printf语句是以随机的非正统顺序输出的。
当(absoluteFinalGrade%1)的范围从0.45到0.49时,我希望输出以红色打印。这是因为由于给了我几百行输出,所以我希望那些重要的行能脱颖而出。但是,system.err.printf似乎以一种非正统的方式干扰了我的输出。可以使用其他方法使我的文字脱颖而出吗?
import java.util.Scanner;
public class FinalChemistryGradeCalculator {
public static void main (String [] args) {
Scanner input = new Scanner (System.in);
Scanner input2 = new Scanner (System.in);
double termGrade;
double examinationGrade;
double examinationMarkScore;
double examinationMarkTotal;
double lowestTestGrade;
double lowestTestMarkScore;
double lowestTestMarkTotal;
double initialFinalGrade;
double absoluteFinalGrade;
System.out.printf("Input the term grade.%n");
termGrade = input.nextDouble();
System.out.printf("%nThe term grade is %.2f.%n", termGrade);
System.out.printf("%nInput the lowest test mark score.");
lowestTestMarkScore = input.nextDouble();
System.out.printf("%nInput the lowest test mark total.");
lowestTestMarkTotal = input.nextDouble();
lowestTestGrade = (lowestTestMarkScore/lowestTestMarkTotal) * 100;
System.out.printf("%nThe lowest test grade is %.2f.%n", lowestTestGrade);
System.out.printf("%nInput the examination mark total.");
examinationMarkTotal = input.nextDouble();
for (examinationMarkScore = 0; examinationMarkScore <= examinationMarkTotal; examinationMarkScore += 0.5) {
examinationGrade = (examinationMarkScore/examinationMarkTotal) * 100;
initialFinalGrade = (termGrade * 0.7) + (examinationGrade * 0.3);
if (lowestTestGrade < examinationGrade) {
absoluteFinalGrade = initialFinalGrade - (lowestTestGrade * 0.05) + (examinationGrade * 0.05);
}
else {
absoluteFinalGrade = initialFinalGrade;
}
if (absoluteFinalGrade % 1 >= 0.45 && absoluteFinalGrade % 1 <= 0.49) {
System.err.printf("%n%n--------------------------------------------------------------------------------------------------------------");
System.err.printf("%nTerm Grade: %.2f ||||| Examination Grade: %.2f (%.1f/%.1f) ||||| Lowest Test Grade: %.2f (%.1f/%.1f)", termGrade, examinationGrade, examinationMarkScore, examinationMarkTotal, lowestTestGrade, lowestTestMarkScore, lowestTestMarkTotal);
System.err.printf("%nInitial Final Grade: %.2f ||||| Absolute Final Grade: %.2f", initialFinalGrade, absoluteFinalGrade);
System.err.printf("%n--------------------------------------------------------------------------------------------------------------");
System.err.flush();
}
else {
System.out.printf("%n%n--------------------------------------------------------------------------------------------------------------");
System.out.printf("%nTerm Grade: %.2f ||||| Examination Grade: %.2f (%.1f/%.1f) ||||| Lowest Test Grade: %.2f (%.1f/%.1f)", termGrade, examinationGrade, examinationMarkScore, examinationMarkTotal, lowestTestGrade, lowestTestMarkScore, lowestTestMarkTotal);
System.out.printf("%nInitial Final Grade: %.2f ||||| Absolute Final Grade: %.2f", initialFinalGrade, absoluteFinalGrade);
System.out.printf("%n--------------------------------------------------------------------------------------------------------------");
System.out.flush();
}
}
}
}
答案 0 :(得分:-2)
您可以使用jansi:
System.out.println( ansi().eraseScreen().render("@|red Hello|@ @|green
World|@") );
此例子是从引Jansi Github README
请注意,这不会大概从Eclipse或任何IDE包装的工作。