By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,003 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Java equivalent of cin

P: n/a
I am new to Java programming and I was wondering if anyone can tell me the
java equivalent to a cin>>...; that is normally used in c++. I want to get
user input and automatically assign it to a variable. So in other words what
would be the equivant java statement of this c++ statement:

1: cout<<"Enter a number.";
2: cin>>x; //This is what I really want to know. I already know the java
equivalent of the first statement.

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Gregory W. Ernest" <Ge*****@optonline.net> wrote in
news:KR*****************@fe10.lga:
I am new to Java programming and I was wondering if anyone can tell me
the java equivalent to a cin>>...; that is normally used in c++. I
want to get user input and automatically assign it to a variable. So
in other words what would be the equivant java statement of this c++
statement:

1: cout<<"Enter a number.";
2: cin>>x; //This is what I really want to know. I already know the
java equivalent of the first statement.


Are you looking for something like?

byte [] b=new byte[255];
System.in.read(b);

I strongly recommend that you download the J2SDK HTML documentation and
put in on your machine. You then have the complete class heirarchy
reference available to view at will.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #2

P: n/a
I am new to Java programming and I was wondering if anyone can tell me
the java equivalent to a cin>>...; that is normally used in c++. I
want to get user input and automatically assign it to a variable. So
in other words what would be the equivant java statement of this c++
statement:

1: cout<<"Enter a number.";
2: cin>>x; //This is what I really want to know. I already know the
java equivalent of the first statement.


Are you looking for something like?

byte [] b=new byte[255];
System.in.read(b);

I strongly recommend that you download the J2SDK HTML documentation and
put in on your machine. You then have the complete class heirarchy
reference available to view at will.


That doesn't seem too efficient

Regards
Michael

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.841 / Virus Database: 572 - Release Date: 21/01/2005
Jul 17 '05 #3

P: n/a
"Sharp" <Sh***@SharpAddress.com> wrote in news:YIBId.129830$K7.120029
@news-server.bigpond.net.au:

Are you looking for something like?

byte [] b=new byte[255];
System.in.read(b);

I strongly recommend that you download the J2SDK HTML documentation and put in on your machine. You then have the complete class heirarchy
reference available to view at will.


That doesn't seem too efficient


As opposed to what? Use of a fixed length buffer? explicit necessity to
type cast the result to some other type?...what then?

IMHO, streams under java are ugly to begin with.
Jul 17 '05 #4

P: n/a
"Wiseguy <no***@all.com>" wrote in comp.lang.java:
"Sharp" <Sh***@SharpAddress.com> wrote in news:YIBId.129830$K7.120029
@news-server.bigpond.net.au:
Are you looking for something like?

byte [] b=new byte[255];
System.in.read(b);

I strongly recommend that you download the J2SDK HTML documentation
and put in on your machine. You then have the complete class
heirarchy reference available to view at will.
That doesn't seem too efficient


As opposed to what? Use of a fixed length buffer? explicit necessity to
type cast the result to some other type?...what then?


Perhaps "java.io.BufferedReader" might address the efficiency concern?
I wonder if "Sharp" needs to read line-by-line.
IMHO, streams under java are ugly to begin with.


Streams aren't the only thing, but then again there are many ugly
things in many languages. I think Java's Generics are even uglier, but they
will prove to be very beneficial in the long run.

--
Randolf Richardson, pro-active spam fighter - rr@8x.ca
Vancouver, British Columbia, Canada

Sending eMail to other SMTP servers is a privilege.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.