//运算符优先级问题
private static void youxianji(){
//表达式 a = i++ 它等价于 a = i ; i = i + 1;
//表达式 a = ++i 它等价于 i = i + 1; a = i;
int k = 0;
int ret = ++k + k++ + ++k + k;
System.err.println(ret); //8
k = 0;
ret = ++k + k++;
System.err.println(ret);//2
System.err.println("k="+k);//2
k = 0;
ret = ++k + k++ + ++k ;
System.err.println(ret);//5
System.err.println("k="+k);//3
}
//运算符问题
private static void yushuanfu(){
int i1 = 10, i2 = 10;
System.err.println("i1 + i2 = " + i1 + i2); //1010
System.err.println("i1 - i2 = " + (i1 - i2)); //0
System.err.println("i1 * i2 = " + i1 * i2); //100
System.err.println("i1 / i2 = " + i1 / i2); //1
}
public class Test {
public void myMethod(String str) {
System.err.println("string");
}
public void myMethod(Object obj) {
System.err.println("object");
}
public static void main(String[] args) {
Test t = new Test();
t.myMethod(null); //String
}
public static void date() {
Date date = new Date(); //20120211
System.err.println(date.getMonth() + " " + date.getDate());//1 11
}
public static void Mathtest() {
double val = 11.5;
System.err.println(Math.round(val)); //12
System.err.println(Math.floor(val)); //11.0
System.err.println(Math.ceil(val)); //12.0
}
public void method() {
System.err.println(super.getClass().getName());
System.err.println(this.getClass().getSuperclass().getName());
}
public static void trueisfalse() {
String str1 = new String("abc");
String str2 = new String("abc");
System.err.println(str1.equals(str2)); //true
StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = new StringBuffer("abc");
System.err.println(sb1.equals(sb2)); //false
}
//结果return 1
public int method1() {
int x = 1;
try {
return x;
} finally {
++x;
}
}
//结果reutrn 2
public int method2() {
int x = 1;
try {
return x;
} finally {
return ++x;
}
}
//结果return false;
public static boolean method3() {
try {
return true;
} finally {
return false;
}
}
public static void inttureorfalse() {
Integer i1 = 127;
Integer i2 = 127;
System.err.println(i1 == i2); //true
i1 = 128;
i2 = 128;
System.err.println(i1 == i2);//false
}
public static void stringtrueorfalse() {
String str1 = "a";
String str2 = "a";
String str3 = new String("a");
System.err.println(str1 == str2); //true
System.err.println(str1 == str3); //false
str3 = str3.intern();
System.err.println(str1 == str3); //true
}
public static void sub() {
System.err.println(12 - 11.9 == 0.1); //false
}
public static void set() {
Set
set = new HashSet();
set.add("one");
set.add("two");
set.add("three");
set.add("four");
set.add("five");
for (Iterator it = set.iterator(); it.hasNext();) {
System.err.println(it.next());
}
// 结果
// two
// five
// one
// three
// four
}