System.in 是System类下面有一个静态的成员变量in。它的类型是InputStream。
代表的是标准键盘输入流。也就是键盘录入数据。
Scanner是对其进行了封装,提供了各种转换功能。方便我们获取到想要的数据类型的数据。
(3)要掌握的两个功能:
A:返回int类型
public int nextInt()
B:返回String类型
public String nextLine()
public String next()
2:String类的概述和使用(掌握)
(1)由多个字符组成的一串数据。
(2)构造方法:
A:String s = new String();
B:String s = new String(byte[] bys);
C:String s = new String(byte[] bys,int startIndex,int count);
D:String s = new String(char[] chs);
E:String s = new String(char[] chs,int startIndex,int count);
F:String s = new String(String s2);
G:String s = "hello";
(3)面试题:
A:字符串一旦被赋值就不能被改动。
注意:这里的改动指的是字符串的内容,而不是字符串对象的引用。
B:String s = new String("hello");和String s = "hello";有区别吗?是什么呢?
有。
前者创建了两个对象。
后者创建了一个对象。
C:看程序,写结果
String s1 = new String("hello");
String s2 = new String("hello");
System.out.println(s1==s2);
System.out.println(s1.equals(s2));