Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA: If I want to run this code in my program, how do I modify it to compile? I

ID: 3786786 • Letter: J

Question

JAVA: If I want to run this code in my program, how do I modify it to compile? If an exam score entered is <0, it will print the error message and end the program. My program is not compiling with the || statements.


if (exam1 || exam2 || exam3 < 0){
System.out.println("Invalid input. Exam scores must be between 0 and 100!");
return;
}

if (average >= 90){
grade = ('A');
}
else
if (average >= 80){
grade = ('B');
}
else
if (average >= 70){
grade = ('C');
}
else
if (average >= 60){
grade = ('D');
}
else
if (average >= 0){
grade = ('F');
}

Explanation / Answer

if ((exam1 < 0 ) || (exam2 < 0 ) || (exam3 < 0)){
System.out.println("Invalid input. Exam scores must be between 0 and 100!");
return;
}

if (average >= 90){
grade = ('A');
}
else
if (average >= 80){
grade = ('B');
}
else
if (average >= 70){
grade = ('C');
}
else
if (average >= 60){
grade = ('D');
}
else
if (average >= 0){
grade = ('F');
}