![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2008
Posts: 3
Rep Power: 0
![]() |
Help why doesnt it work
Im new to Java and i am creating simple programs to start out but i ran into a problem with this:
My compiler says "M:\Java\DataType.java:22: integer number too large: 4000000002 k = 4000000002 ; // k to 4,000,000,002 ^ 1 error" I Use JCreator. and the Code is : class datatype { public static void main(string args[]) { double SQUARE_ROOT_OF_TWO = 1.414214; int i; // i as an integer long j; // j as a long integer long k; // k as a long integer float n; // n floating point number long Speed_of_light; long Speed_of_Sound; long e; Speed_of_light = (3.00e8); e = Speed_of_light; Speed_of_Sound = (340.292); i = 3; // initialize i to 3; j = -2048111; // j to -2,048,111 // The problem is This Line k = 4000000002 ; // k to 4,000,000,002 //The problem is this line i cant see whats wrong with it. n = (float) 1.887; // n to 1.887 System.out.println( SQUARE_ROOT_OF_TWO); System.out.println( "i = " + i); System.out.println( "j = " + j); System.out.println( "k = " + k); System.out.println( "n = " + n); System.out.println(e); System.out.println(Speed_of_Sound); } } // end of class DataType |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 548
Rep Power: 4
![]() |
Re: Help why doesnt it work
You're using a signed long integer, which can only represent values from -2^31 to 2^31, use unsigned long to use numbers from 0 to 2^32-1.
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#3 |
|
Highly Adaptive Penguin
Join Date: May 2005
Location: United States
Posts: 249
Rep Power: 4
![]() |
Re: Help why doesnt it work
I'm not trying to me a stickler, but for future reference, place your code in code tags. It makes it alot easier to read.
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2008
Posts: 3
Rep Power: 0
![]() |
Re: Help why doesnt it work
Thanks Guys and next time i will and i probably will =D
Edit: I tried using the unsigned long but it gave me an error: M:\Java\DataType.java:12: not a statement unsigned long k; // k as a long integer ^ M:\Java\DataType.java:12: ';' expected unsigned long k; // k as a long integer |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
Re: Help why doesnt it work
different "number types" have limits http://java.sun.com/docs/books/tutor...datatypes.html
there is no unsigned in java
__________________
i dont know much about programming but i try to help |
|
|
|
|
|
#6 | |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 548
Rep Power: 4
![]() |
Re: Help why doesnt it work
Quote:
![]() Disregard my last post, OP ![]()
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Mar 2008
Posts: 3
Rep Power: 0
![]() |
Re: Help why doesnt it work
i think you were thinking about c++ since they are similar. or Visual Basic
and can anyone tell me whats wrong with the problem i have |
|
|
|
|
|
#8 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 816
Rep Power: 4
![]() |
Re: Help why doesnt it work
You have to tell the compiler that 4000000002 is a long, rather than an integer. Sticking an L on the end does that:
k = 4000000002L ; // k to 4,000,000,002 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| hello, I'd like to write a program for my work. | blake_jl | Community Introductions | 13 | Nov 23rd, 2007 4:31 PM |
| tables dont work in firefox; they work in IE | angry_asian | HTML / XHTML / CSS | 3 | Aug 5th, 2006 6:00 PM |
| Help:::::::: Why Wont This Work?????? | paulchwd | ASP | 1 | Jul 10th, 2005 1:34 PM |
| Can't get loop to work | rockybalboa | Java | 3 | Mar 20th, 2005 6:19 PM |
| 40 Things you'd like to say out loud at work | big_k105 | Coder's Corner Lounge | 11 | Jan 25th, 2005 2:13 AM |