This week's book giveaway is in the Other Languages forum.We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# working with numbers

Arash Ashl
Greenhorn
Posts: 9
Hi, I am new to this website and java programming
had a couple of question from you gents

what's the difference of using nextLong(radix) and nextLong()?

and why if I have a loop like :
long i;
if(i>1000000000000000000)
{blah blah}

it says The literal 1000000000000 of type int is out of range!!!?

thanks guys

Jeff Verdegan
Bartender
Posts: 6109
6
• 1
ar nb wrote:Hi, I am new to this website and java programming
had a couple of question from you gents

what's the difference of using nextLong(radix) and nextLong()?

What do the docs say?

and why if I have a loop like :
long i;
if(i>1000000000000000000)
{blah blah}

it says The literal 1000000000000 of type int is out of range!!!?

thanks guys

Any integer literal is taken as an int unless otherwise specified. Since that number is outside the range for int, you get that message. If you want that literal to be interpreted as a long, put an L at the end:

Arash Ashl
Greenhorn
Posts: 9

the doc says : radix - the radix used to interpret the token as an int value
now my question is if i don't type radix in parenthesis, it will interpret the token as float or something else?!

got it(for the second part of the answer).

Arash Ashl
Greenhorn
Posts: 9
the problem I'm working on is about getting a 13-16 digit number, and then manipulate the digits of the number...like add the second number from the right to the 5th number from the left....is there anyway easier than using % and / to get it done?! like is it possible to take the number that user gives us, and put it in a int array? that would make it so easy...but my knowledge about this language is not enough yet lol

Steve Fahlbusch
Bartender
Posts: 605
7
Greetings,

Two points......

First, please change your ar nb to an actual name, this is a professional site and they like people acting professionally.

Second, if you looked at the javadoc, you should have seen that this method passed the parms to another method (long.parseLong()). Look at the javadocs there where they have a set of actual examples that should answer your question. Still confused, then post again.

-steve

Steve Fahlbusch
Bartender
Posts: 605
7

You can always accept the number as a string, then do string manipulation.

-steve

Arash Ashl
Greenhorn
Posts: 9
yeah I received a private message about that too...changed it right away
it is my name now, it's Persian it's not fake

I did look at javadoc, but it's a huge list of methods and classes, and for me, a beginner, I don't really know how to centralize my search in javadoc...or where to look for specifically in all that info!

can you please tell me in which class I in docjava I can find long.parseLong() method?

about your last post...if I get the it as a string, how can I manipulate it as numbers?! how can I add them together, divide them by 2 or...??

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15492
43
• 1
Welcome to the Ranch!

Arash Ashl wrote:what's the difference of using nextLong(radix) and nextLong()?

Which methods are you talking about - in which class are these methods? Do you mean class java.util.Scanner?

Arash Ashl wrote:can you please tell me in which class I in docjava I can find long.parseLong() method?

That would in the class java.lang.Long (<- you can click that to go to the documentation).

Arash Ashl wrote:the doc says : radix - the radix used to interpret the token as an int value
now my question is if i don't type radix in parenthesis, it will interpret the token as float or something else?!

Do you understand what "radix" means? It means the base of the number system you use.

For example, we normally use decimal numbers, which have radix = 10.

You could also use for example hexadecimal numbers, which have radix = 16, and which use the digits 0, 1, 2, 3, ..., 8, 9, A, B, C, D, E, F.

Arash Ashl
Greenhorn
Posts: 9
if I get a string from a user, how can I separate the digits and characters of it?! like if I want him to enter a name, and he enters something like jo7n, how can can I tell that's not a name?

Arash Ashl
Greenhorn
Posts: 9
I guess I shouldn't have asked that
I'll come up with a better question....

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15492
43
• 1
Arash Ashl,
Your post was moved to a new topic.