My First Java Statement Post
My first Java if/else statement post
GradeCalculator {
public static void main(String[] args) {
int percent=93;
//calculates the grade received in AP Physics based on a percentage score earned in the class before the final trimester curve.
if(percent<50){
System.out.println("Sorry, didnt pass");
}
else if(percent>=50 && percent<60){
System.out.println("You earned a D");
}
else if(percent>=60 && percent<70){
System.out.println("You earned a C");
}
else if(percent>=70 && percent<85){
System.out.println("You earned a B");
}
else if(percent>=85 && percent<90){
System.out.println("You earned an A");
}else if(percent>=90 && percent<100){
System.out.println("You're the best!");
}else if(percent=100){
System.out.println("You're too good!");
}else{
System.out.println("Try again.");
}
}
}
Else if statements provide another layer to if statements, running all of the conditional statements until one holds true (otherwise, if false, the code segment in the else statement will be ran)
You're the best!
If and else statements are boolean operators and help to specify if a conditions is either true or false, and runs segments of code based on which boolean operator holds true.
int percent = 25;
if(percent<50){
System.out.println("Sorry, didnt pass");
}
If loops run a condition based on a boolean condition; either true or false. Above, the code ran because the value percent held true.