基礎2

露水上的青蛙發表於2013-09-11

package nine;

import java.util.Random;

class Value{
 int m;
}
public class eleven {
 static void prt(String s){
  System.out.println(s);
 }
 public static void main(String args[]){
  int i=1;
  System.out.println("i= "+(++i));
  System.out.println("i= "+(i++));
  
  Integer n1 = new Integer(22);
  Integer n2 = new Integer(22);
  System.out.println(n1==n2);//false 物件內容相同,但是控制程式碼不同,二者比較的正好是控制程式碼
  System.out.println(n1!=n2);
  System.out.println(n1.equals(n2));
  
  Value a1 = new Value();
  Value a2 = new Value();
  a1.m = a2.m = 99;
  System.out.println(a1.equals(a2));//控制程式碼肯定不同了
  System.out.println(a1.m==a2.m);
  
  Random rand = new Random();
  int b1 = rand.nextInt()%100;
  int b2 = rand.nextInt()%100;
  prt("b1 = " + b1);
  prt("b2 = " + b2);
  prt("b1 > b2 is " + (b1 > b2));
  prt("b1 = b2 is " + (b1 == b2));
  prt("b1 != b2 is " + (b1 != b2));
  prt("(b1 < 10) && (b2 < 10) is " + ((b1<10)&&(b2<10)));
 }
}