• Post Reply Bookmark Topic Watch Topic
  • New Topic

I can't find out what is wrong , code.  RSS feed

 
Minjae Kim
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




when I compile this one, it goes mad...
 
Tim Cooke
Marshal
Posts: 4039
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minjae Kim wrote:when I compile this one, it goes mad...

You're going to need to be a bit more specific than that. See ItDoesntWorkIsUseless (<-- click)

Do you get compiler errors?
Does it not do what you expected?
What did you expect it to do?
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

There is nothing wrong with the code. As TC says, you need to tell us what happens.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. You didn't say what "goes mad" means, or what you were expecting to happen, but I think it should compile fine. The "^" operator is not used for exponentiation in Java, as I'm guessing you expected: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

The java.lang.Math class has a method for exponentiation. Of course, x will be too large to be stored in an int long before the 500th iteration.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wouldn't be the 500th iteration. The loop would terminate when x passes 500.

The correct way to square a number in any language is not to use a² but a × a.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minjae Kim wrote:

The ^ operator is not the power operator (this does not compute x squared). Instead, it's bitwise exclusive OR.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!