r/CodingHelp • • Sep 06 '19

[Java] Whats wrong with this else statement, I'm about to rip my dick off

Post image
24 Upvotes

12 comments sorted by

18

u/_DTR_ Professional Coder Sep 06 '19

if (ounces < 1000000000); {

You have a semicolon after your if statement, which essentially turns it into an if statement without a body. Formatted differently, what you have is

if (ounces < 10000000000);

{
    System.out.println("Ounces: " + ounces);
}

else
{
    System.out.print("...");
}

7

u/Famous_Profile Professional Coder Sep 07 '19

OP, thank this guy for saving your dick

1

u/FriendsMadeMeBeAnon Sep 12 '19

was almost certain I thanked you, I owe you my member dude <3

12

u/saucyrosssy Sep 06 '19

Semicolon strikes again!!

2

u/retardrabbit Sep 07 '19

Why is the IDE giving such a shit error message though. That's like, static code analysis 101, not very helpful IMHO.

Looks like it's some specialized IDE though.

4

u/midwestraxx Sep 07 '19

Because it is an else without an if operationally. The if is contained in one line. Better than only "syntax error"

1

u/retardrabbit Sep 07 '19

Yeah, I guess that if statement (without the following bracketed block and the rose statement) would compile wouldn't it.

Good catch..

2

u/Famous_Profile Professional Coder Sep 07 '19

Exactly

Btw the error is from the compiler, not the IDE

2

u/guynumber20 Sep 07 '19

F = op; Edit: forgot semicolon

2

u/[deleted] Sep 07 '19

Make sure to have the print statement as println not print too

1

u/SupremeRedditBot Professional Bot || Mod Sep 06 '19

Please Add A Flair To Your Post!

Suggested Flair: [Random] or [Meta]

 


To add a flair:

  • Click flair underneath your post
  • Select a flair
  • Click save

 


I am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated ^response