import java.util.ArrayList;
import static java.lang.Math.random;
/**
* JDK1.5的新特性
* @author zhaoguoli
* @version v1.0 2009-07-02 晚1点 create
*/
public class TestJDK5New {
public int sum(int... n) { //传过来n为一个int型数组
int tempSum = 0;
for(int option : n) {
tempSum+=option;
}
return tempSum;
}
public enum MyColors {
red,
black,
blue,
green,
yellow
}
/**
* @param args
*/
public static void main(String[] args) {
// 自动装箱与拆箱
Integer i = 10;
System.out.println(i);
int j = i;
System.out.println(j);
//更优化的for循环
String[] names = {"BadBoy","GoodBoy","HappyGirl","sadGirl"};
for(String option: names) {
System.out.println(option);
}
/*
* for + 加泛型
*/
ArrayList<String> animals = new ArrayList<String>();
animals.add("Dog");
animals.add("Cat");
animals.add("Chick");
animals.add("Cow");
for(String option : animals) {
System.out.println(option);
}
//参数可变的方法 相当于传递了不固定的参数
TestJDK5New testJDK5New = new TestJDK5New();
System.out.println(testJDK5New.sum(1,2));
System.out.println(testJDK5New.sum(1,2,3));
System.out.println(testJDK5New.sum(1,2,3,4));
System.out.println(testJDK5New.sum(1,2,3,4,5));
// printf方法, 对应c语言的printf
int x = 10;
int y = 20;
int sum = x + y;
System.out.printf("%d + %d = %d",x,y,sum);
System.out.println("");
//枚举
MyColors color = MyColors.red;
for(MyColors option : MyColors.values()) {
System.out.println(option);
}
System.out.println(color);
// 静态引用
double xxx = random();
System.out.println(xxx);
}
}
import static java.lang.Math.random;
/**
* JDK1.5的新特性
* @author zhaoguoli
* @version v1.0 2009-07-02 晚1点 create
*/
public class TestJDK5New {
public int sum(int... n) { //传过来n为一个int型数组
int tempSum = 0;
for(int option : n) {
tempSum+=option;
}
return tempSum;
}
public enum MyColors {
red,
black,
blue,
green,
yellow
}
/**
* @param args
*/
public static void main(String[] args) {
// 自动装箱与拆箱
Integer i = 10;
System.out.println(i);
int j = i;
System.out.println(j);
//更优化的for循环
String[] names = {"BadBoy","GoodBoy","HappyGirl","sadGirl"};
for(String option: names) {
System.out.println(option);
}
/*
* for + 加泛型
*/
ArrayList<String> animals = new ArrayList<String>();
animals.add("Dog");
animals.add("Cat");
animals.add("Chick");
animals.add("Cow");
for(String option : animals) {
System.out.println(option);
}
//参数可变的方法 相当于传递了不固定的参数
TestJDK5New testJDK5New = new TestJDK5New();
System.out.println(testJDK5New.sum(1,2));
System.out.println(testJDK5New.sum(1,2,3));
System.out.println(testJDK5New.sum(1,2,3,4));
System.out.println(testJDK5New.sum(1,2,3,4,5));
// printf方法, 对应c语言的printf
int x = 10;
int y = 20;
int sum = x + y;
System.out.printf("%d + %d = %d",x,y,sum);
System.out.println("");
//枚举
MyColors color = MyColors.red;
for(MyColors option : MyColors.values()) {
System.out.println(option);
}
System.out.println(color);
// 静态引用
double xxx = random();
System.out.println(xxx);
}
}