This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes working with numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "working with numbers" Watch "working with numbers" New topic
Author

working with numbers

Arash Ashl
Greenhorn

Joined: Mar 04, 2013
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Mar 04, 2013
Posts: 9
hey thanks for reply

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

Joined: Mar 04, 2013
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

Joined: Sep 18, 2000
Posts: 557
    
    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

Joined: Sep 18, 2000
Posts: 557
    
    7

Your next question.......

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

-steve
Arash Ashl
Greenhorn

Joined: Mar 04, 2013
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Arash Ashl
Greenhorn

Joined: Mar 04, 2013
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?

any hint on where to start with?
Arash Ashl
Greenhorn

Joined: Mar 04, 2013
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

Arash Ashl,
Your post was moved to a new topic.
Please ask a new question in a new topic, instead of adding it to a topic about another, unrelated question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: working with numbers
 
Similar Threads
locked cookie
NX: URLyBird 1.1.3
Campaign for deletion of "Word Association" thread.
what is the output
Simple SQL question