Solved

Read as integer...

Posted on 1998-05-06
2
167 Views
Last Modified: 2010-04-16
OK, I want to have an interface to read a keyboard input to be understood as integer or double, to perform some calculation upon that number. What's the easiest way to do it ?
0
Comment
Question by:ggmg
2 Comments
 
LVL 5

Accepted Solution

by:
fontaine earned 50 total points
ID: 1220597
System.in provides you with an InputStream to read data from the standard input stream, i.e. the keyboard. As you need a higher level of abstraction, build a DataInputStream upon it and use its readInt(), readByte(), etc., methods

Example:

DataInputStream in = new DataInputStream(System.in);

try {
int anInt = in.readInt();
double aDouble = in.readDouble();
} catch (IOException e) {
e.printStackTrace();
 }
0
 

Author Comment

by:ggmg
ID: 1220598
Thanks a lot...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now