如何从java控制台输入带空格的字符串?
/**按行读取 */import java.io.*;public class SystemInTest {
public static void main(String[] args) { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String str; try { str = stdin.readLine(); System.out.println(str); } catch (IOException e) { e.printStackTrace(); } }}Java控制台输入带空格的字符串,读取的时候只要按照行来读取,就可以获取到输入的空格,下面是示例:/**按行读取 */import java.io.*;public class SystemInTest {public static void main(String[] args) { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));//建立从控制台输入的类 String str; try { str = stdin.readLine();//读取一行 System.out.println(str); } catch (IOException e) { e.printStackTrace(); } }}
- import java.util.Scanner;
- public class encode2013
- {
- public static void main(String[] args){
- String inString;
- String delimiter;
- Scanner scan = new Scanner(System.in);
- inString=scan.nextLine();
- delimiter=scan.next();
- inString= inString.replace(" ",delimiter);
- System.out.println(inString);
- }