package shoucong;
import java.util.Scanner;
public class apples {
public static void main(String args[]) {
Scanner buckey = new Scanner(System.in);
System.out.println(buckey.nextLine());
}
}
Java中Scanner类中的方法next()和nextLine()都是吸取输入台输入的字符,区别:
- next()不会吸取字符前/后的空格/Tab键,只吸取字符,开始吸取字符(字符前后不算)直到遇到空格/Tab键/回车截止吸取;
-
nextLine()吸取字符前后的空格/Tab键,回车键截止。
import java.util.Scanner; import java.util.Vector; public class Main{ public static void main(String args[]) { Scanner reader=new Scanner(System.in); String s1=reader.nextLine(); String s2=reader.next(); System.out.println(s1); System.out.println(s2); } }
可以看到next()只吸取了askldfj字符,空格后面的都舍弃了!