import java.io.IOException;
public class EchoStdin {
public static void main(String[] args) throws IOException {
System.out.print("Please type a message and press enter: ");
int c = "\n";
while ((c = System.in.read()) != "\n") {
System.out.print((char) c);
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = "q";
while (true) {
System.out.print("Please type a message (Q/q to quit) and press enter:");
text = br.readLine();
if (text.equalsIgnoreCase("q")) {
System.out.println("We have decided to exit the program");
break;
} else {
System.out.println("We typed: " + text);
}
}
}
}
更多建議: