473,409 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Taking input in java

hello!
I am new to java but as compared to any other language like c or c++
taking input in java is difficult but I tried using Keyborad.readInt(); for reading the inputs given by the keyborad,but still not able to properly execute it.
Can anyone help me regarding taking input in java'
Thanks in advance!!!!!!!
May 25 '07 #1
7 5285
r035198x
13,262 8TB
hello!
I am new to java but as compared to any other language like c or c++
taking input in java is difficult but I tried using Keyborad.readInt(); for reading the inputs given by the keyborad,but still not able to properly execute it.
Can anyone help me regarding taking input in java'
Thanks in advance!!!!!!!
If you are using 1.5 or higher (you should be), have a look at how to use the Scanner to take input from users
May 25 '07 #2
dmjpro
2,476 2GB
Welcome to TSDN.

you can also use like ....

Expand|Select|Wrap|Line Numbers
  1. InputStreamReader in = new InputStreamReader(System.in);
  2. //Here System.in is the standard input stream and that is keyboard.
  3.  
kind regards.
dmjpro.
May 25 '07 #3
JosAH
11,448 Expert 8TB
Welcome to TSDN.

you can also use like ....

Expand|Select|Wrap|Line Numbers
  1. InputStreamReader in = new InputStreamReader(System.in);
  2. //Here System.in is the standard input stream and that is keyboard.
  3.  
kind regards.
dmjpro.
That doesn't help you much, you still have to do the scanning yourself that way.
As r035198x already wrote: use a scanner to do the dirty work:
Expand|Select|Wrap|Line Numbers
  1. Scanner in= new Scanner(System.in);
  2. if (in.hasNextInt())
  3.    System.out.println("next int in stream: "+in.nextInt());
  4. else
  5.    System.out.println("no int as the current token in stream");
You have to upgrade to at least Java 1.5 (1.6 is better) to be able to use a Scanner.

kind regards,

Jos
May 25 '07 #4
dmjpro
2,476 2GB
so JOASH Scanner is much more better than InputStreamReader????

kind regards.
dmjpro.
May 25 '07 #5
JosAH
11,448 Expert 8TB
so JOASH Scanner is much more better than InputStreamReader????

kind regards.
dmjpro.
Erm, yes, that's what I wrote basically in my previous reply. A Scanner still isn't
a full blown lexical analyzer but it's much better than any home brew tokenizer
based on an InputStream or Reader.

kind regards,

Jos
May 25 '07 #6
RJaya
1
I am new to java.Programming for input in java is difficult but I tried using Keyborad.readInt(); It is appeared to read it but System.out.println gives a totally different value. Can anyone help me regarding taking input in java'
Thanks in advance
Nov 17 '07 #7
JosAH
11,448 Expert 8TB
I am new to java.Programming for input in java is difficult but I tried using Keyborad.readInt(); It is appeared to read it but System.out.println gives a totally different value. Can anyone help me regarding taking input in java'
Thanks in advance
Have you read the previous replies? Use a Scanner object to do the dirty work:
it can read several types of numbers and strings and (almost) whatever you want.

kind regards,

Jos
Nov 17 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Christopher R. Barry | last post by:
I need to search and replace multiple words in one pass of an input stream or string. For example, given the input: "The quick brown fox jumped over the lazy dog's back" and given the...
1
by: wqhdebian | last post by:
As far as I know,when encrypt or decrypt ,a key must first be got,and the key is first generate by a tool or from SecurityRandom,that means I can not generate the same key with the same input.Does...
7
by: Basil Fawlty | last post by:
I need help and suggestions on how to modify the below program to get two numbers from user input using a input dialog box. B/c I'm a total newbie with next to no programming experience, I'm not...
0
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
1
by: LC's No-Spam Newsreading account | last post by:
I have the following arrangement working under Netscape 3 / Unix, IE6 / Win and Konqueror / Linux, but NOT under Netscape 7 Unix or Mozilla Linux (silently fails) nor under Netscape 4 Unix (fails...
30
by: Richard | last post by:
Level: Java newbie, C experienced Platform: Linux and Win32, Intel Another programmer and I are working on a small project together. He's writing a server process in Java that accepts input...
6
by: AZRebelCowgirl73 | last post by:
Here is my problem: I have two java files: One named Car.java and the other named CarDealerApp.java: In the CarDealerApp program, I read in through user input the make, model, year and price of...
11
by: arnuld | last post by:
C takes input character by character. I did not find any Standard Library function that can take a word as input. So I want to write one of my own to be used with "Self Referential Structures" of...
2
by: vijaykumardahiya | last post by:
Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter are not store in Ms-Access. I store the input parameter through Standard Action <jsp:useBean>. jsp:useBean call a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.