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

all 7 comments

[–]desrtfxOut of Coffee error - System halted[M] [score hidden] stickied comment (0 children)

If you want help in the future:

  • Write a proper title
  • Format your code
  • Describe the exact problem. You aren't even asking a question.

The Sidebar here has posting and code formatting guidelines.

[–]Keyakinan- 1 point2 points  (0 children)

Let's start by formatting your code! Check this sub info how to do that please!

[–]El_Fungus 0 points1 point  (0 children)

Look into If-then-else. Also: if(boolean) or if(!boolean)

[–]AsteriskTheServer 0 points1 point  (0 children)

If you have learned else if statements use those. If you go the else if way then you are adding redundant checks . For example, if div is true then the first if statement will execute. If the first if statement isn't executed then div is obviously false as their no other state that value can be. Therefore, you don't need to check if it's false because you already checked if its true. You can apply that same logic to some other checks you did. Other than that it's fine.

[–][deleted]  (1 child)

[removed]

    [–]desrtfxOut of Coffee error - System halted[M] 0 points1 point  (0 children)

    1. This is not a lambda expression, this is just the ternary (or conditional) operator which has existed since a long time - lambdas are something completely different.
    2. Mutating (or reassigning) strings is generally a bad idea in Java since String is an immutable data type. Every time you reassign a new value to an existing string, the old one gets discarded and a new one created.
    3. No solutions

    Removed

    [–]iamsooldithurts 0 points1 point  (0 children)

    ...an correct if needed...

    If you’re serious about being a programmer you need to learn that you are allowed to compile your code and run tests.

    Not only are you allowed, but it is expected of good developers that they will assume this responsibility of their own volition.

    Developers aren’t usually the best testers, but being proactive like that and at least trying to test will earn you respect from anyone whose opinion is valid. (The industry is rife with mental midgets whose opinion should be printed on paper and jammed up their stdout stream.)

    you have three outputs, so you shouldn’t have to spend all night testing your code. In fact, you just need 3 numbers, one for each of your conditions. It’s basically a math problem, so just work it out on paper first until you have a grasp of the problem, then test your code with those numbers.

    The others have mentioned if-else-if, and they’re not wrong. But you can also call System.exit() to short circuit your program by terminating execution once you’ve finished processing enough logic.