Java基础练习题(1)

161 阅读1分钟
/*
 * 分别写出以下的计算值
 * */
int i = 20;
//case 1
System.out.println(i++ + i++);
//case 2
System.out.println(i++ + ++i);
//case 3
System.out.println(++i + i++);
//case 4
System.out.println(++i + ++i);
/*
 * 分别写出以下的计算值
 * */
int j = 20;
//case 1
System.out.println(j-- + j--);
//case 2
System.out.println(j-- + --j);
//case 3
System.out.println(--j + j--);
//case 4
System.out.println(--j + --j);

/*
 * 此程序编译是否有误,如果有,会报什么错
 * */
public class Question0003 {
  
  public static void hello() {
    System.out.println("hello world");
  }
  
  public static void main(String[] args) {
    ((Question0003)null).hello();
  }
  
}
/*
 * 分别写出以下的计算值
 * */
public class Question0004 {
  
  public static void main(String[] args) {
    String a1 = "hello world";
    String a2 = "hello " +"world";
    String a3 = new String(a2);
    
    System.out.println(a1==a2);
    System.out.println(a2==a3);
    System.out.println(a1==a3);
  }
  
}

/*
 * 分别写出以下的计算值
 * */
public class Question0005 {
  
  public static void main(String[] args) {
    Integer a1 = 10;
    Integer a2 = 10;
    Integer a3 = 200;
    Integer a4 = 200;
    
    System.out.println(a1==a2);
    System.out.println(a3==a4);
  }
  
}