Results 1 to 8 of 8
Thread: Can't see what is wrong
- 05-04-2011, 05:11 AM #1
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
- 05-04-2011, 05:19 AM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,236
- Rep Power
- 13
Error says int is out of bounds
Java Code:System.out.println(Integer.MAX_VALUE);
Artel shows how to use a long constant, which is the real answer you are looking for.Last edited by camickr; 05-04-2011 at 05:29 AM.
- 05-04-2011, 05:22 AM #3
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
This will compile without error:
Java Code:import java.lang.Math; public class test { public static void main (String[] args) { long givenNum = 600851475143[COLOR="Red"]l[/COLOR]; System.out.println(givenNum); for (int i = 1; i < Math.floor(givenNum/2); ++i) { } } }
Last edited by Artel; 05-04-2011 at 05:25 AM.
-
I second Artel's recommendation and explanation but with one slight change: always use an upper case L not a lower case l at the end of your long literal as the lower case l is too easily mistaken for a one.
- 05-05-2011, 03:05 AM #5
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
Thank you so much
- 05-05-2011, 03:31 AM #6
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
Ok this is pesky
Even with the L gives an error saying out of int range
-
It works fine for me.
- 05-05-2011, 04:43 AM #8
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 4Last Post: 06-11-2013, 02:37 AM -
if anyone could help. what am i doing wrong?
By glina126 in forum New To JavaReplies: 12Last Post: 02-20-2011, 12:52 AM -
What is wrong?
By phantom06 in forum New To JavaReplies: 2Last Post: 02-02-2011, 07:08 PM -
can't see where it went wrong..
By Yakg in forum New To JavaReplies: 5Last Post: 01-31-2011, 01:19 PM -
Something is Wrong O.o
By Spidermonkey in forum Advanced JavaReplies: 16Last Post: 11-14-2010, 05:33 AM
Bookmarks