Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++ cin.get() in Java please!

1,679 views
Skip to first unread message

Rachel Lara Mackie

unread,
Oct 15, 2001, 6:18:20 AM10/15/01
to
Can somone please tell me the Java equivalent of the above? So, before
executing the next line of code the user would need to hit [Enter]. Need
specifics too, such as instantiating and importing to do this!

Many thanks :)


Jon Skeet

unread,
Oct 15, 2001, 6:21:06 AM10/15/01
to

Use System.in() - you probably want to wrap a BufferedReader round it
and read a line at a time.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Rachel Lara Mackie

unread,
Oct 15, 2001, 6:30:11 AM10/15/01
to
So it's something like:

line = System.in(); // not sure, please correct if wrong
BufferedReader input = new BufferredReader(line);
if (input == null) // null being Enter??
// continue executing

Thanks :)

"Jon Skeet" <sk...@pobox.com> wrote in message
news:MPG.1634c8f07...@mrmog.peramon.com...

Jon Skeet

unread,
Oct 15, 2001, 6:50:31 AM10/15/01
to
Rachel Lara Mackie <rlm...@student.monash.edu> wrote:
> So it's something like:
>
> line = System.in(); // not sure, please correct if wrong
> BufferedReader input = new BufferredReader(line);
> if (input == null) // null being Enter??
> // continue executing

No, it's more like:

BufferedReader br = new BufferedReader (System.in());

String line = br.readLine();

with appropriate IO exception handling etc.

However, I strongly suggest you learn the basics of Java before trying
this. Ignore console input for the moment, and just write programs that
use console output. Then use files for input and output, then go for
console input.

0 new messages