Hi,
I want to let user input a
string, display it and then terminate the program.
I have the following code:
import java.io.*;
public class MyCat {
public static void main (String args[])
throws IOException {
int b;
while ((b = System.in.read()) != -1) {
System.out.print((char)b);
}
System.out.println();
}
}
The result is that it requires input continueously without termination.
I changed it:
import java.io.*;
public class MyCow {
public static void main (String args[])
String b;
System.in.read(b);
System.out.print(b);
}
It shows a lot of errors. I don't understand why do I need to use Exception in the first case, the while loop is to read the char one by one.
In C++, I just cin >> a; and cout << a; to get and display the string a. How should I do it in
Java?
Thanks
Andrew