public class Test8 {
public static void main(String[] args) {
/*//1. 初始化原始数组
Integer[] originalArray = {4,2,4,6,1,2,4,7,8};
//2. 初始化HashSet集合,因为HashSet集合使用了Map集合的key部分,所以可以自动的去除重复的key
Set<Integer> setArray = new HashSet<Integer>(originalArray.length);
//3. 将原始数组添加到HashSet集合中,这个过程就去除了重复的值了
setArray.addAll(Arrays.asList(originalArray));
//4. 打印输出结果
System.out.println(Arrays.toString(setArray.toArray(new Integer[setArray.size()])));*/
//显示的最大数+1
/*int total = 10;
for (int i = 1; i <= total; i++) {
//1. 打印空格
for (int x = 1; x <= i; x++) {
System.out.print(" ");
}
//2. 打印左边
for (int k = total - i; k >= 1; k--) {
System.out.print(k);
}
//3. 打印右边,从2开始
for (int j = 2; j <= total - i; j++) {
System.out.print(j);
}
//4. 打印换行
System.out.println();
}*/
//实例化一个内部类
Person p = new Test8().new Person();
p.setAge(20);
p.speak();
}
//内部类
class Person{
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
void speak(){
System.out.println(age);
}
}
}
|