java - 'else' without 'if' despite use of braces -
i've been getting 'else' without 'if' error following code , i'm not sure why. i've used braces , i'm confused.
if(mean >= 90 && mean <= 100){ grade = 'o';} else{ if(mean >= 80 && mean < 90) grade = 'e';} else{ if(mean >= 70 && mean < 80) grade = 'a';} else{ if(mean >= 55 && mean < 70) grade = 'p';} else{ if(mean >= 40 && mean < 55) grade = 'd';} else{ if(mean < 40) grade = 't';}
i think not using right structure if-else if statement in java. should :
if (testscore >= 90) { grade = 'a'; } else if (testscore >= 80) { grade = 'b'; } else if (testscore >= 70) { grade = 'c'; } else if (testscore >= 60) { grade = 'd'; } else { grade = 'f'; }
you can go check out link further infos : https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html
Comments
Post a Comment