119-面向对象(高级)-包装类的理解_基本数据类型与包装类间的转换_哔哩哔哩_bilibili
1.包装类
2.基本转包装方式
2.1new方式
源码
2.2valueof()
3.包装转基本
4.基本类型和包装类型的默认值不一样
比如boolean默认false
Boolean默认null(对象)
通过初始值的不一样,可以分辨某些对象是否初始化过还是归零了
5.自动装箱拆箱
6.String和其他类型转换
import java.util.Scanner;
import java.util.Vector;
public class Main {
//求最大
public static void main(String[] args) {
Main m = new Main();
System.out.println( m.maxScoreFunc() );
}
int maxScoreFunc2(){
Vector v = new Vector();
Scanner scan = new Scanner(System.in);
int maxScore = 0;
while(true){
System.out.println("print in");
int intScore = scan.nextInt();
if(intScore < 0){
break;
}
// Integer score = Integer.valueOf(intScore);
//自动装箱成对象放入向量
v.addElement(intScore);
maxScore = intScore > maxScore? intScore:maxScore;
}
for(int i=0;i < v.size();i++){
//取对象拆箱
Object objScore = v.elementAt(i);
int intScore = (Integer) objScore;
if(maxScore - 10 > intScore){
System.out.println("B等级");
}
}
return maxScore;
}
int maxScoreFunc(){
Scanner scan = new Scanner(System.in);
int maxScore = 0;
while(true){
System.out.println("print in");
int intScore = scan.nextInt();
if(intScore < 0){
break;
}
maxScore = intScore > maxScore? intScore:maxScore;
}
//System.out.println(maxScore);
return maxScore;
}
}