Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can scanner class take negative numbers?
Posted
Comments
Sergey Alexandrovich Kryukov 26-Dec-14 19:21pm    
Negative of what types? What's wrong with reading original Java documentation?
—SA

Apparently, these are the methods nextBigInteger, nextDouble, nextFloat, nextInt, etc., depending on the type you want to parse:
http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html[^].

—SA
 
Share this answer
 
Comments
CristianCruz503 26-Dec-14 21:12pm    
so it don't matter what method I use? Thank You very much.
Sergey Alexandrovich Kryukov 26-Dec-14 21:40pm    
You are welcome.
It depends on what do you expect to have in the file and what numeric types do you want to use. For example, of you have something like -127 to 127, it could be the smallest integer type; of decimal point is involved, it could be floating-point type, and so on...
—SA
You can take negative number as input by all methods above mentioned but I would recommended not to use Scanner because it is damn slow. Always use BufferedReader to take input & PrintWriter for output.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900