Java Input/Output: Reading User Input from Console
public class Main { public static void main(String[] args) { try { // create a BufferedReader object to read input from console BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// prompt the user to enter their name
System.out.print('Enter your name: ');
// read the user's input
String name = reader.readLine();
// print a greeting message to the user
System.out.println('Hello, ' + name + '!');
} catch (IOException e) {
System.out.println('An error occurred: ' + e);
}
} }
原文地址: https://www.cveoy.top/t/topic/nwwo 著作权归作者所有。请勿转载和采集!