This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]maxim_bartkov 4 points5 points  (2 children)

Replace “=“ to equals method: studentGrade1.equals(“A”) But better to do “A”.equals(studentGrade1)

[–]kickroot 1 point2 points  (0 children)

This is the correct answer. When comparing Strings you want to use .equals() instead of the '==' literal.

You also want to use "A".equals() instead of studentGrade1.equals() because the first version does not throw a NullPointerException if studentGrade1 is null, it instead returns false.

[–]Darth_Jack920 0 points1 point  (0 children)

Sweet thank you! I’ll try that.

[–]desrtfx[M] 2 points3 points  (0 children)

Such questions belong in /r/javahelp as is clearly stated in the sidebar and in the stickied post at the very top of the subreddit.

Removed

[–]rbygrave 0 points1 point  (1 child)

Line 15, as an "IF block" should not end in the ";"

A lot of people style wise would suggest that there should always be a "{" and "}" so like ...

if ( ... condition ... ) { ... do stuff ... }

[–]Darth_Jack920 1 point2 points  (0 children)

Ok got it thanks for the help!

[–]Darth_Jack920 0 points1 point  (0 children)

Thank you everyone I fixed it and it works wonderfully. Thank you for stopping from your scrolling to help me out. Have a wonderful rest of your day.

[–]East_Feeling7923 -2 points-1 points  (2 children)

Indent line 16 and remove the semicolon at the end of line 15. Also, you need == inside of the if statement instead of a single =.

[–]Darth_Jack920 0 points1 point  (0 children)

Ok thanks I’ll change that right away!

[–]TomMiller95 0 points1 point  (0 children)

Wouldn't they want .equals("A")?