Re: The greeting code in Java
On Jun 19, 4:19 pm, A=E9ris <ae...@imirhil.fr> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
public class Main {
public static void main(final String[] args) throws IOExc=
eption {
final BufferedReader in = new BufferedR=
eader(
new InputStreamReader(Sys=
tem.in));
String s;
while ((s = in.readLine()) != null &&=
s.length() > 0) {
System.out.print("Please =
enter your first name:");
System.out.println("Hello=
, " + s);
}
}
}
- --
Aeris
Thank you for your immediate answer. I ran your program and
it doesn't exactly did as the C++ version. First,
a message is printed and ask the user name, then the greeting
message is appeared on screen. In you program, no asking message
is appeared and the user can't figure out what should he/she do?
after username data entry we'll have the following output:
Aeris
Please enter your first name:Hello, Aeris
Also, please note In C++, the I/O operation using << and >>
are formatted, but in both code, we read the input, until
we reach the end of line.
You used the BufferedReader and InputStreamReader classes.
From point of educational view, do you think my code or your code
is as simple as the C++ version?
Regards,
-- Saeed