Java解惑
下面的程序你真的懂几个?
package cn.xwy.test;
import java.util.Random;
import java.util.regex.Pattern;
public class Test {
private static Random random = new Random();
public static final int END = Integer.MAX_VALUE;
public static final int START = END - 100;
public static void main(String[] args) {
// System.out.println(12345+5432L);
// System.out.println(Long.toHexString(0x100000000L + 0xcaefbabe));
// System.out.println((int)(char)(byte) -1 );
// char x = 'X';
// int i = 0;
// System.out.println(true ? x : 0);
// System.out.println(false ? i : x);
/*
* 给出变量x和i的声明使如下语句合法 x = x + 1; 但是使如下语句不合法 x += 1;
*
* Object x = "Buy"; String i = "Effective Java!";
*
*/
// System.out.println("H" + "a");
// System.out.println('H' + 'a');
// String letterd = "ABC";
// char[] numbers = {'1','2','3'};
Object numbers = new char[] {'1','2','3'};
System.out.println(letterd + "easy as " + numbers);
// System.out.println(letterd + "easy as " + String.valueOf(numbers));
// final String pig = "length: 10";
// final String dog = "length: " + pig.length();
// System.out.println("Animal are ==:" + pig == dog);
// System.out.println("Animal are ==:" + (pig == dog));
// System.out.println("pig.equals(dog):"+pig.equals(dog));
// System.out.println("a\u0022.length()+\u0022b".length());
// System.out.println("a".length() + "b".length());
// byte bytes[] = new byte[256];
// for(int i=0; i<256; i++){
// bytes[i] = (byte)i;
// System.out.print(bytes[i] + " ");
// }
// System.out.println();
// String string = new String(bytes);
// for(int i=0; i<string.length(); i++){
// System.out.print((int)string.charAt(i) + " ");
// }
// System.out.println(Test.class.getName().replaceAll(".", "/") +
// ".class");
// System.out.println(Test.class.getName().replaceAll(Pattern.quote("."),
// "/") + ".class");
// System.out.println("aaaa");
// http://www.google.com;
// System.out.println("bbb");
// StringBuffer word = null;
// System.out.println(random.nextInt(3));
// switch (random.nextInt(3)) {
// case 1:
// word = new StringBuffer('p');
// break;
// case 2:
// word = new StringBuffer('G');
// break;
// default:
// word = new StringBuffer('M');
// break;
// }
// System.out.println(word);
// word.append('a');
// word.append('i');
// word.append('n');
// System.out.println(word);
// int j = 0;
// for(int i=0; i<100; i++){
// j = j++;
// }
// System.out.println(j);
// int count = 0;
// System.out.println(END - START);
// for(int i=START;i <= END; i++){ //i <= END 和 i < END的区别
// count ++;
// }
// System.out.println(count);
// int i = 0;
// while(-1 << i != 0)
// i++;
// System.out.println(i);
//将下面的循环变成无限循环
//可以用任何被计算为无穷大的浮点算术表达式来初始化i,例如
// double i = 1.0 / 0.0;
//最好能够利用标准类库提供的常量
// double i = Double.POSITIVE_INFINITY;
// while(i == i + 1){
// }
//将下面的循环变成无线循环
// double i = 1.0 / 0.0;
// double i = Double.NaN;
// while(i != i){
// }
//将下面的循环变成无线循环
// String i = "ss";
// while(i != i + 0){
// }
//将下面的循环变成无限循环
// short i = -1;
// while(i != 0){
// i >>>= 1;
// System.out.println(i);
// }
//将下面的循环变成无限循环
//数值比较是值的比较,而判等比较是引用标志的比较
// Integer i = new Integer(0);
// Integer j = new Integer(0);
// System.out.println(i);
// System.out.println(j);
// System.out.println(i<=j);
// System.out.println(i>=j);
// System.out.println(i!=j);
// while(i<=j && j<=i && i!=j){
//
// }
//同上
// int i = Integer.MIN_VALUE;
// long i = Long.MIN_VALUE;
// while(i!=0 && i==-i){
// }
}
}