You are viewing a single comment's thread from:

RE: Help me with this JAVA bug!

in #java6 years ago

First of all, the code in the Pastebin is different than the one on the picture...
Your problem in the Pastebin version is, that your checkArm method ALWAYS(!) returns false. Even if the number is armstrong number, you always return false - on the line 27.

The code on the picture doesn't work because of 2 reasons:

  • Line 30 should be n = n / 10;
  • Replace line 29 with a = a + (b*b*b); - not sure if that's the power of 3 in Java. I replaced it with this and it worked

Also, just the effectivity advice. You can just do return (a ==c);
That expression already evaluates into True or False. What you basically do is "If True then return True ". It works but it's not really the way how you should do it :) You save 3 lines like this and code looks better.

Keep learning! :)

Coin Marketplace

STEEM 0.21
TRX 0.26
JST 0.040
BTC 101165.24
ETH 3668.48
USDT 1.00
SBD 3.16