1.Scanner类的概述 public final class Scanner
其实是一个文本扫描器
Scanner sc = new Scanner(System.in)
hasNextInt()方法的概述
hasNext() 判断录入是否为字符串
int i = sc.nextInt();
if (hasNextInt) {
int i = sc.nextInt();
System.out.print(i);
}else { System.out.println(录入错误);}
hasNextInt() 判断键盘录入的数是否是int类型的,是就返回ture,不是返回false
用于解决键盘录入非int型报错问题.
public String():空构造
public String(byte [] bytes):把字节数组转成字符串 将计算机读的懂的转换成我们看的懂的
public String(byte [] bytes,int index,int length):把字节数组的一部分转成字符串
public String(char [] value,int index,int count):将字符数组转换成字符串
面试题
String s1 = "abc" String s2 = "abc" abc进的是常量池,常量池中没有这个字符串时,会创建,有时会直接用.
String s1 = new String("abc")创建几个对象,两个,一个在堆内存,一个在常量池
java中存在常量优化机制 同byte b =3+4;编译时就变成了7,把7赋值给b,常量优化机制