Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 11th, 2008, 7:50 PM   #1
fireblaze118
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0 fireblaze118 is on a distinguished road
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
fireblaze118 is offline   Reply With Quote
Old Mar 11th, 2008, 8:01 PM   #2
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 548
Rep Power: 4 Benoit is on a distinguished road
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
Benoit is offline   Reply With Quote
Old Mar 11th, 2008, 8:07 PM   #3
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 247
Rep Power: 4 Brent is on a distinguished road
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.
Brent is offline   Reply With Quote
Old Mar 11th, 2008, 8:08 PM   #4
fireblaze118
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0 fireblaze118 is on a distinguished road
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
fireblaze118 is offline   Reply With Quote
Old Mar 11th, 2008, 8:39 PM   #5
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: olympia,WA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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
mrynit is offline   Reply With Quote
Old Mar 11th, 2008, 8:50 PM   #6
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 548
Rep Power: 4 Benoit is on a distinguished road
Re: Help why doesnt it work

Quote:
Originally Posted by mrynit View Post
different "number types" have limits http://java.sun.com/docs/books/tutor...datatypes.html

there is no unsigned in java
what???

Disregard my last post, OP
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Mar 11th, 2008, 8:56 PM   #7
fireblaze118
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0 fireblaze118 is on a distinguished road
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
fireblaze118 is offline   Reply With Quote
Old Mar 12th, 2008, 1:10 AM   #8
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
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
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:07 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC