You are viewing a single comment's thread from:

RE: Help me with this JAVA bug!

in #java6 years ago

@matkodurko is correct. Some other things to consider:

The ^ caret operator in java is bitwise exclusive or (XOR) and not the exponent operator Link to docs
You can either use Math.pow(), probably much easier, multiply your b, by itself 3 times. So change line 29 on your photo above to:
a = a + (b * b * b);

Note: I use the round brackets to make the order of operations unambiguous. They're not needed since multiplication is resolved before addition but I think having the brackets makes the code easier to read.

Also a note on style: this doesn't affect your result, but generally if you're going to copy the value of a method's parameter for later use then it's usually easier to read if you change your local copy rather than the function parameters. How this affects your code, from line 27 onwards you exchange all n's for c's and c's for n's. That'll mean that on your check, before your are returning true or false, you will be comparing a with n. That's a bit easier to read imo and also reduces the risk of issues when you deal with pass-by-reference parameters (in java or some other language).

Coin Marketplace

STEEM 0.15
TRX 0.15
JST 0.028
BTC 53699.14
ETH 2213.00
USDT 1.00
SBD 2.28