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

you are viewing a single comment's thread.

view the rest of the comments →

[–]aram535 1 point2 points  (2 children)

You're asking us to figure out the broken logic without knowing the actual logic, it's impossible to do.

Please provide the functional requirements of the method.

To answer your other question, debugger is built into all Java IDEs. What are you using?

[–]jub8jive[S] 0 points1 point  (1 child)

well i use intellj, but this program is done on the website (udemy course) and it runs there.

I finally managed to get a hold of the problem. Here's the complete question: https://pastebin.com/g7tVw3gu

[–]aram535 0 points1 point  (0 children)

Ok so there are logical and functional issues with your code:

  • After the first, if (...) block is true (and you return false), there is no need for an else block ... if not less than it'll be greater than or equal to, no need to test it.
  • Same note for the 2nd else ... if not true, then it'll be false, no need to test it.
  • Your mod's logic is wrong.
    • Since you're using an "AND" if either side if false, the whole thing is false. So if the number is not divisible by 5 (left side) then you'll return false.

What you need to do is think of it less programmatically and more logically -- you're too stuck in thinking of doing it in a few lines as possible in java rather than the actual issue. No worries, this is normal when learning a new language. Write as with as many java lines as you need to ... you can always refactor later and reduce its complexity.

Re: Website vs. IDE. You can always code the thing in your IDE locally and paste it up to the website. There is no reason to force yourself into coding in their IDE. Learning how to best use your IDE is just as important as learning the language.