男人中的路易威登

导航

JDK5.0新特性2

1.运行环境

jdk1.8.0_77 Intellij IDEA2018.3 x64

——————————————————————————————————————————————————————————————————

2.主要目标(回顾)

静态导入

自动装箱/拆箱

for-each循环

可变参数 枚举

 

——————————————————————————————————————————————————————————————————

 

3.代码展示

public static void main(String[] args) {

    out.println("hello");
out.println(abs(-23.1));
out.println(PI);

}
================================================================================================================================
public static void main(String[] args) {
int i=300;
Integer a1=300;
Integer a2=300;
System.out.println(a1 == a2);
System.out.println(a1.equals(a2));

System.out.println("=====================================================");

Integer a3 = 100;
Integer a4 = 100;
System.out.println(a3 == a4);
System.out.println(a3.equals(a4));

System.out.println("=====================================================");
Integer a5 = Integer.valueOf(103);
Integer a6 = Integer.valueOf(103);
System.out.println(a5==a6);


==========================================================================================================================================


public static void main(String[] args) {
int[] a = new int[]{10,20,30,40,50};
for(int i:a){
System.out.println(i);
}

List b = new ArrayList();
b.add("aaa");
b.add("bbb");
b.add("ccc");
b.add("ddd");
for(Object s:b){
System.out.println(s);
}

}

=====================================================================================================================================

public static void main(String[] args) {
fun("aa");

fun("bb",1);

fun("cc",1,2,3);

int[] ary = new int[]{10,20,30};
fun("dd",ary);

}

public static void fun(String s,int... x){
System.out.println("----------------------");
System.out.println(x.length);
for(int i:x){
System.out.println(i);
}
}

======================================================================================================================

public static void main(String[] args) {
Season spring = Season.春天;

Season summer = Season.夏天;


Season[] seasons = Season.values();
for(Season s : seasons){
System.out.println("字符串形式:" + s.name());
System.out.println("数字形式:" + s.ordinal());
}


Scanner sc = new Scanner(System.in);
System.out.println("请输入一个季节:");
String temp = sc.next();

Season se = Season.valueOf(temp);

se.show();

System.out.println("请选择一个季节编号:");
int no = sc.nextInt();

Season se1 = Season.values()[no];

se1.show();
}


 
 
 

 

 

4.运行结果

 

hello
23.1
3.141592653589793

****************************************************************************************************************************

false

true
=====================================================
true
true
=====================================================
true

****************************************************************************************************************************

10
20
30
40
50
aaa
bbb
ccc
ddd

****************************************************************************************************************************

0
----------------------
1
1
----------------------
3
1
2
3
----------------------
3
10
20
30

****************************************************************************************************************************

字符串形式:春天
数字形式:0
字符串形式:夏天
数字形式:1
字符串形式:秋天
数字形式:2
字符串形式:冬天
数字形式:3
请输入一个季节:
夏天
夏天很炎热
请选择一个季节编号:
2
秋天很干燥

****************************************************************************************************************************

 

 

5.心得

失败是什么?没有什么,只是更走近成功一步;成功是什么?就是走过了所有通向失败的路,只剩下一条路,那就是成功的路。

 

posted on 2020-08-24 19:03  男人中的路易威登  阅读(111)  评论(0编辑  收藏  举报