字符代码表
0-9:48-57;
A-Z:65-90;
a-z:97-122;
空格:32;
扫描器
next()和nextLine()区别:
一般输入字符串时会出现next()和nextLine()。
- 当使用next()时,不会读取字符前/后的空格或者Tab键,只会读取空格键/Tab键/回车截止读取;
- 当使用nextLine()时,读取字符前后的空格/Tab键,有回车键时截止读取。
测试代码
输入代码
s1:(空格)123(空格+Tab键)aaa(空格)
s2:(空格)123(空格+Tab键)aaa(空格)
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s1 = sc.next();
String s2 = sc.nextLine();
System.out.println("s1:" + s1);
System.out.println("s2:" + s2);
}
}
输出结果为:
s1:123
s2: aaa
s2前面只有一个Tab键