/**按行读取 */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) }页面中用&nbsp代表一个空格 (中间的&符号与n之间有个空格,你用的时候去掉就行了原因 在这个输入框中默认就给我解析成空格了)
Java类中 System.out.println(" ")双引号中间想要几个空格就敲几次空格键
1、“ ”2、在Java中有两种占位符%和{},
%后面可以是d、f、s等中间也可以加其他参数。
// %s占位符,输出字符串
String username = "user1"
int num = 3
System.out.printf("%s您好,您是第%s位访客\n", username, num)
// prints user1您好,您是第3位访客