Results 1 to 8 of 8
Thread: Can't see what is wrong
- 05-04-2011, 04:11 AM #1
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
- 05-04-2011, 04:19 AM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,145
- Rep Power
- 5
Try the following to see what the maximum value is that you use as an int constant:Error says int is out of bounds
Edit: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 04:29 AM.
- 05-04-2011, 04:22 AM #3
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
This will compile without error:
I'm kind of a beginner at Java too, so I probably don't know the real explanation, but I think when you assign "600851475143" to a long value, it treats 600851475143 as a literal int, so you have to put an "L" at the end of it so Java will treat it as a long literal instead of an int literal.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 04: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, 02:05 AM #5
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
Thank you so much
- 05-05-2011, 02: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, 03:43 AM #8
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
if anyone could help. what am i doing wrong?
By glina126 in forum New To JavaReplies: 12Last Post: 02-19-2011, 11:52 PM -
What is wrong?
By phantom06 in forum New To JavaReplies: 2Last Post: 02-02-2011, 06:08 PM -
can't see where it went wrong..
By Yakg in forum New To JavaReplies: 5Last Post: 01-31-2011, 12:19 PM -
Something is Wrong O.o
By Spidermonkey in forum Advanced JavaReplies: 16Last Post: 11-14-2010, 04:33 AM -
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks