在java中用键盘输入多个字符串,并将它们打印出来

2024-12-22 23:50:55
推荐回答(2个)
回答1:

package test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {

public static void main(String[] args) {
System.out.println("请输入字符串:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String str = br.readLine();
System.out.println(str);
} catch (IOException e) {
e.printStackTrace();
}

}

}

回答2:

public static void main(String[] args) {
System.out.println("请输入字符串:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String str = br.readLine();
System.out.println(str);
} catch (IOException e) {
e.printStackTrace();
}

}