LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2006, 09:21 AM   #1
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Rep: Reputation: 30
reading from standard input in java


I want to read for example a int or a float from stdin in java.
something like
Code:
int i;
scanf("%d",&i);
in c.

any idea on how to do this ?
i'm a beginner in java so try to give me some time
thanks!
 
Old 10-17-2006, 10:16 AM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
If you want to read input, try:
Code:
java.util.Scanner inputReader = new java.util.Scanner(System.in);

int number;
System.out.print("Prompt:> ");
number = inputReader.nextInt();
There's other ways to do this, but this is the easiest, and the cleanest in my opinion.

 
Old 10-17-2006, 10:44 AM   #3
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
works great... thank you. for start it is very confusing for my the large amount of implemented function that i have to learn to get along. in c i was used to make all from scratch

Last edited by spank; 10-17-2006 at 10:46 AM.
 
Old 10-17-2006, 06:58 PM   #4
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
It's all good. One thing I would suggest doing if you're going to get serious into Java programming, is to pick up Java In A Nutshell. It covers all of the basic classes (no GUI classes - java.awt.* & javax.swing.*).

Sidenote: I just noticed the price of Java In A Nutshell - used & new copies for less than $20 USD!!! When I got that book last year, I paid about $70 CAD after tax!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to append characters to standard input (telnet script) cep21 Linux - General 1 07-10-2006 01:02 PM
Standard Input in Perl Program eachow Linux - General 2 11-17-2005 12:16 AM
parsing standard input with bash arosales Programming 3 07-16-2005 10:42 AM
utf , standard output / input and grep too Fascistchicken Linux - Software 2 11-05-2004 08:52 AM
stty: standard input: Inappropriate ioctl for device fwalthard Linux - General 0 07-14-2003 02:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration