I get this java.util.MissingFormatArgumentException error. I\'m not sure how to
ID: 3752691 • Letter: I
Question
I get this java.util.MissingFormatArgumentException error. I'm not sure how to round the value if print f doesn't work in this way.
SumofWeights2 = (Exam1Weight + Exam2Weight + FinalExamWeight + LabsWeight + ProjectsWeight + AttendanceWeight + QuizzesWeight);
SumofWeightxScore = (Exam1Weight*Exam1Score + Exam2Weight*Exam2Score + FinalExamScore*FinalExamWeight + LabAvg*LabsWeight + ProjectAvg*ProjectsWeight + QuizAvg*QuizzesWeight + AttendanceAvg*AttendanceWeight);
CurrentScore = (SumofWeightxScore/SumofWeights2);
x = (HundredxFinalOverallScore - SumofWeightxScore);
y = (100 - SumofWeights2);
AvgToFinalLetterGrade = (x/y);
System.out.printf("Current Grade Score:%1.2f " + CurrentScore);
System.out.println();
ERROR CODE BELOW:
Current Grade Score:Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '%1.2f'
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at GradeCalculator.main(GradeCalculator.java:251) this is line: System.out.printf("Current Grade Score:%1.2f " + CurrentScore);
Explanation / Answer
Please correct this: " System.out.printf("Current Grade Score:%1.2f " + CurrentScore); "
in to
" System.out.printf("Current Grade Score:%1.2f " , CurrentScore); "
Instead of '+' use ',' beacause if you are using printf you need to specify the placeholders as printf parameters.
That is instead of using string concatenation, specify the value to replace the placeholder.
Please upvote if you like the answer and comment if you need any further information in this regard.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.