易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

第3章 操作符/3.1 更简单的打印语句

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 原来:System.out.println("Hello,It's: ");
  2. 现在:
    1. import static net.mindview.until.Print.*;
    2. print("Hello,It's: ");
  3.  

第3章 操作符/3.2 使用Java操作符

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 包括:+、-、*、/、==、=、+=、-+、*=、/=
  2. 适用于基本类型的操作符:+、-、*、/、==、=、+=、-+、*=、/=
  3. 适用于对象的操作符:==、=、+=

第3章 操作符/3.3 优先级

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符


第3章 操作符/3.4 赋值

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 源代码:
    //: HelloDate.java
    import java.util.*;
    //import static net.mindview.until.Print.*;
    /** the first Thinking in java example program
      * display a string and today's date
      * @author wengyongsheng 
      * @version 4.0 
    */
    public class HelloDate{
    	/**
    	* @param args array of string arguments
    	*/
      public static void main(String []args) {
      System.out.println("Hello,It's: ");
      System.out.println(new Date());
    //  print("Hello,It's: ");
    }
    }
    
    class Tank{
    	 int level;
    }
    
    class Assignment{
    	public static void main(String []args) {
    		Tank t1 = new Tank();
    		Tank t2 = new Tank();
    		t1.level = 9;
    		t2.level = 47;
    		System.out.println("1:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);
        t1 = t2;
        System.out.println("2:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);
    		
    		t1.level = 27;
    		System.out.println("3:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);                   		                   
    	}
    }

     

  2. 结果输出:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

 


第3章 操作符/3.4 赋值/3.4.1 方法调用中的别名问题

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 源代码:
    //: HelloDate.java
    import java.util.*;
    //import static net.mindview.until.Print.*;
    /** the first Thinking in java example program
      * display a string and today's date
      * @author wengyongsheng 
      * @version 4.0 
    */
    public class HelloDate{
    	/**
    	* @param args array of string arguments
    	*/
      public static void main(String []args) {
      System.out.println("Hello,It's: ");
      System.out.println(new Date());
    //  print("Hello,It's: ");
    }
    }
    
    class Tank{
    	 int level;
    }
    
    class Assignment{
    	public static void main(String []args) {
    		Tank t1 = new Tank();
    		Tank t2 = new Tank();
    		t1.level = 9;
    		t2.level = 47;
    		System.out.println("1:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);
        t1 = t2;
        System.out.println("2:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);
    		
    		t1.level = 27;
    		System.out.println("3:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);                   		                   
    	}
    }
    
    class Letter{
    	 char c;
    }
    
    class PassObject{
    	static void f(Letter y){
    		y.c = 'z';
    	}
    	public static void main(String []args) {
    		Letter x = new Letter();
    		System.out.println("1:x.c= " + x.c);
    		x.c = 'a';
    		System.out.println("2:x.c= " + x.c);
    		f(x);
    		System.out.println("3:x.c= " + x.c);
    	}
    }

     

  2. 输出结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

第3章 操作符/3.5 算术操作符

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  • 例子源代码:
    //: HelloDate.java
    import java.util.*;
    //import static net.mindview.until.Print.*;
    /** the first Thinking in java example program
      * display a string and today's date
      * @author wengyongsheng 
      * @version 4.0 
    */
    public class HelloDate{
    	/**
    	* @param args array of string arguments
    	*/
      public static void main(String []args) {
      System.out.println("Hello,It's: ");
      System.out.println(new Date());
    //  print("Hello,It's: ");
    }
    }
    
    class Tank{
    	 int level;
    }
    
    class Assignment{
    	public static void main(String []args) {
    		Tank t1 = new Tank();
    		Tank t2 = new Tank();
    		t1.level = 9;
    		t2.level = 47;
    		System.out.println("1:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);
        t1 = t2;
        System.out.println("2:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);
    		
    		t1.level = 27;
    		System.out.println("3:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);                   		                   
    	}
    }
    
    class Letter{
    	 char c;
    }
    
    class PassObject{
    	static void f(Letter y){
    		y.c = 'z';
    	}
    	public static void main(String []args) {
    		Letter x = new Letter();
    		System.out.println("1:x.c= " + x.c);
    		x.c = 'a';
    		System.out.println("2:x.c= " + x.c);
    		f(x);
    		System.out.println("3:x.c= " + x.c);
    	}
    }
    
    class MathOps{
    	public static void main(String []args) {
    		Random rand = new Random(47);
    		int i , j , k;
    		j = rand.nextInt(100) + 1;
    		System.out.println("j = " + j);
    		k = rand.nextInt(100) + 1;
    		System.out.println("k = " + k);
    		i = j + k;
    		System.out.println("i = " + i);
    		
    		float u , v , w;
    		u = rand.nextFloat();
    		System.out.println("u = " + u);
    		v = rand.nextFloat() ;
    		System.out.println("v = " + v);
    		w = u + v;
    		System.out.println("w = " + w);
    	}
    }

     

  • 例子输出结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

第3章 操作符/3.5 算术操作符/3.5.1 一元加、减操作符

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. x -= a;
  2. x *= a;
  3. x += a;

第3章 操作符/3.6 自动递增和递减

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

    • 前缀式:先自己运算,后参与其它操作
    • 后缀式:先参与其它操作,后自己运算
    • 举例:
      1. 源代码:
        //: HelloDate.java
        import java.util.*;
        //import static net.mindview.until.Print.*;
        /** the first Thinking in java example program
          * display a string and today's date
          * @author wengyongsheng 
          * @version 4.0 
        */
        public class HelloDate{
        	/**
        	* @param args array of string arguments
        	*/
          public static void main(String []args) {
          System.out.println("Hello,It's: ");
          System.out.println(new Date());
        //  print("Hello,It's: ");
        }
        }
        
        class Tank{
        	 int level;
        }
        
        class Assignment{
        	public static void main(String []args) {
        		Tank t1 = new Tank();
        		Tank t2 = new Tank();
        		t1.level = 9;
        		t2.level = 47;
        		System.out.println("1:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
            t1 = t2;
            System.out.println("2:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
        		
        		t1.level = 27;
        		System.out.println("3:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);                   		                   
        	}
        }
        
        class Letter{
        	 char c;
        }
        
        class PassObject{
        	static void f(Letter y){
        		y.c = 'z';
        	}
        	public static void main(String []args) {
        		Letter x = new Letter();
        		System.out.println("1:x.c= " + x.c);
        		x.c = 'a';
        		System.out.println("2:x.c= " + x.c);
        		f(x);
        		System.out.println("3:x.c= " + x.c);
        	}
        }
        
        class MathOps{
        	public static void main(String []args) {
        		Random rand = new Random(47);
        		int i , j , k;
        		j = rand.nextInt(100) + 1;
        		System.out.println("j = " + j);
        		k = rand.nextInt(100) + 1;
        		System.out.println("k = " + k);
        		i = j + k;
        		System.out.println("i = " + i);
        		
        		float u , v , w;
        		u = rand.nextFloat();
        		System.out.println("u = " + u);
        		v = rand.nextFloat() ;
        		System.out.println("v = " + v);
        		w = u + v;
        		System.out.println("w = " + w);
        	}
        }
        
        class AutoInc{
        	public static void main(String []args) {
        		int i = 1;
        		System.out.println("i = " + i);
        		System.out.println("++i = " + ++i);
        		System.out.println("i++ = " + i++);
        		System.out.println("i2 = " + i);
        		System.out.println("--i = " + --i);
        		System.out.println("i-- = " + i--);
        		System.out.println("i3 = " + i);
         }
        }
        /* output
        i = 1
        ++i = 2
        i++ = 2
        i2=3
        --i = 2
        i-- = 2
        i3=1
        */

         

      2. 结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

第3章 操作符/3.7 关系操作符/3.7.1 测试对象的等价性

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

    • 概念:操作结果为boolean,如果关系为真,则结果为true,否则为false
    • 包括
    • 测试对象的引用是否相等
      1. 源代码:
        //: HelloDate.java
        import java.util.*;
        //import static net.mindview.until.Print.*;
        /** the first Thinking in java example program
          * display a string and today's date
          * @author wengyongsheng 
          * @version 4.0 
        */
        public class HelloDate{
        	/**
        	* @param args array of string arguments
        	*/
          public static void main(String []args) {
          System.out.println("Hello,It's: ");
          System.out.println(new Date());
        //  print("Hello,It's: ");
        }
        }
        
        class Tank{
        	 int level;
        }
        
        class Assignment{
        	public static void main(String []args) {
        		Tank t1 = new Tank();
        		Tank t2 = new Tank();
        		t1.level = 9;
        		t2.level = 47;
        		System.out.println("1:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
            t1 = t2;
            System.out.println("2:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
        		
        		t1.level = 27;
        		System.out.println("3:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);                   		                   
        	}
        }
        
        class Letter{
        	 char c;
        }
        
        class PassObject{
        	static void f(Letter y){
        		y.c = 'z';
        	}
        	public static void main(String []args) {
        		Letter x = new Letter();
        		System.out.println("1:x.c= " + x.c);
        		x.c = 'a';
        		System.out.println("2:x.c= " + x.c);
        		f(x);
        		System.out.println("3:x.c= " + x.c);
        	}
        }
        
        class MathOps{
        	public static void main(String []args) {
        		Random rand = new Random(47);
        		int i , j , k;
        		j = rand.nextInt(100) + 1;
        		System.out.println("j = " + j);
        		k = rand.nextInt(100) + 1;
        		System.out.println("k = " + k);
        		i = j + k;
        		System.out.println("i = " + i);
        		
        		float u , v , w;
        		u = rand.nextFloat();
        		System.out.println("u = " + u);
        		v = rand.nextFloat() ;
        		System.out.println("v = " + v);
        		w = u + v;
        		System.out.println("w = " + w);
        	}
        }
        
        class AutoInc{
        	public static void main(String []args) {
        		int i = 1;
        		System.out.println("i = " + i);
        		System.out.println("++i = " + ++i);
        		System.out.println("i++ = " + i++);
        		System.out.println("i2 = " + i);
        		System.out.println("--i = " + --i);
        		System.out.println("i-- = " + i--);
        		System.out.println("i3 = " + i);
         }
        }
        /* output
        i = 1
        ++i = 2
        i++ = 2
        i2=3
        --i = 2
        i-- = 2
        i3=1
        */
        
        class Equaivalence{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1 == n2);
        		System.out.println(n1 != n2);
         }
        }
        
        class EqualsMethod{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1.equals(n2));
         }
        }
        
        class Value{
        	int i ;
        }
        class EqualsMethod2{
        	public static void main(String []args) {
        		Value v1 = new Value();
        		Value v2 = new Value();
        	 System.out.println(v1.equals(v2));
         }
        }
        

         

      2. 测试结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符
    • 测试对象的值是否相等
      1. 源代码:
        //: HelloDate.java
        import java.util.*;
        //import static net.mindview.until.Print.*;
        /** the first Thinking in java example program
          * display a string and today's date
          * @author wengyongsheng 
          * @version 4.0 
        */
        public class HelloDate{
        	/**
        	* @param args array of string arguments
        	*/
          public static void main(String []args) {
          System.out.println("Hello,It's: ");
          System.out.println(new Date());
        //  print("Hello,It's: ");
        }
        }
        
        class Tank{
        	 int level;
        }
        
        class Assignment{
        	public static void main(String []args) {
        		Tank t1 = new Tank();
        		Tank t2 = new Tank();
        		t1.level = 9;
        		t2.level = 47;
        		System.out.println("1:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
            t1 = t2;
            System.out.println("2:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
        		
        		t1.level = 27;
        		System.out.println("3:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);                   		                   
        	}
        }
        
        class Letter{
        	 char c;
        }
        
        class PassObject{
        	static void f(Letter y){
        		y.c = 'z';
        	}
        	public static void main(String []args) {
        		Letter x = new Letter();
        		System.out.println("1:x.c= " + x.c);
        		x.c = 'a';
        		System.out.println("2:x.c= " + x.c);
        		f(x);
        		System.out.println("3:x.c= " + x.c);
        	}
        }
        
        class MathOps{
        	public static void main(String []args) {
        		Random rand = new Random(47);
        		int i , j , k;
        		j = rand.nextInt(100) + 1;
        		System.out.println("j = " + j);
        		k = rand.nextInt(100) + 1;
        		System.out.println("k = " + k);
        		i = j + k;
        		System.out.println("i = " + i);
        		
        		float u , v , w;
        		u = rand.nextFloat();
        		System.out.println("u = " + u);
        		v = rand.nextFloat() ;
        		System.out.println("v = " + v);
        		w = u + v;
        		System.out.println("w = " + w);
        	}
        }
        
        class AutoInc{
        	public static void main(String []args) {
        		int i = 1;
        		System.out.println("i = " + i);
        		System.out.println("++i = " + ++i);
        		System.out.println("i++ = " + i++);
        		System.out.println("i2 = " + i);
        		System.out.println("--i = " + --i);
        		System.out.println("i-- = " + i--);
        		System.out.println("i3 = " + i);
         }
        }
        /* output
        i = 1
        ++i = 2
        i++ = 2
        i2=3
        --i = 2
        i-- = 2
        i3=1
        */
        
        class Equaivalence{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1 == n2);
        		System.out.println(n1 != n2);
         }
        }
        
        class EqualsMethod{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1.equals(n2));
         }
        }
        
        class Value{
        	int i ;
        }
        class EqualsMethod2{
        	public static void main(String []args) {
        		Value v1 = new Value();
        		Value v2 = new Value();
        	 System.out.println(v1.equals(v2));
         }
        }
        

         

      2. 测试结果:
        1. 易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符
        2. 易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符
      3. 测试结果说明:因为equals默认比较的引用,由于两个对象都是单独new的,这样结果肯定是不一样的,除非覆盖equals方法,重新定义比较逻辑

第3章 操作符/3.8 逻辑操作符

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 概念:结果也是生成一个boolean值,要么为true,要么为false
  2. 包括:
    1. &&
    2. ||

第3章 操作符/3.8 逻辑操作符/3.8.1 短路

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

    • 概念:指的是如果一部分逻辑运算结果就能确认整个表达式的值则不需要对剩下的逻辑进行运算
    • 举例
      1. 源代码:
        //: HelloDate.java
        import java.util.*;
        //import static net.mindview.until.Print.*;
        /** the first Thinking in java example program
          * display a string and today's date
          * @author wengyongsheng 
          * @version 4.0 
        */
        public class HelloDate{
        	/**
        	* @param args array of string arguments
        	*/
          public static void main(String []args) {
          System.out.println("Hello,It's: ");
          System.out.println(new Date());
        //  print("Hello,It's: ");
        }
        }
        
        class Tank{
        	 int level;
        }
        
        class Assignment{
        	public static void main(String []args) {
        		Tank t1 = new Tank();
        		Tank t2 = new Tank();
        		t1.level = 9;
        		t2.level = 47;
        		System.out.println("1:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
            t1 = t2;
            System.out.println("2:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
        		
        		t1.level = 27;
        		System.out.println("3:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);                   		                   
        	}
        }
        
        class Letter{
        	 char c;
        }
        
        class PassObject{
        	static void f(Letter y){
        		y.c = 'z';
        	}
        	public static void main(String []args) {
        		Letter x = new Letter();
        		System.out.println("1:x.c= " + x.c);
        		x.c = 'a';
        		System.out.println("2:x.c= " + x.c);
        		f(x);
        		System.out.println("3:x.c= " + x.c);
        	}
        }
        
        class MathOps{
        	public static void main(String []args) {
        		Random rand = new Random(47);
        		int i , j , k;
        		j = rand.nextInt(100) + 1;
        		System.out.println("j = " + j);
        		k = rand.nextInt(100) + 1;
        		System.out.println("k = " + k);
        		i = j + k;
        		System.out.println("i = " + i);
        		
        		float u , v , w;
        		u = rand.nextFloat();
        		System.out.println("u = " + u);
        		v = rand.nextFloat() ;
        		System.out.println("v = " + v);
        		w = u + v;
        		System.out.println("w = " + w);
        	}
        }
        
        class AutoInc{
        	public static void main(String []args) {
        		int i = 1;
        		System.out.println("i = " + i);
        		System.out.println("++i = " + ++i);
        		System.out.println("i++ = " + i++);
        		System.out.println("i2 = " + i);
        		System.out.println("--i = " + --i);
        		System.out.println("i-- = " + i--);
        		System.out.println("i3 = " + i);
         }
        }
        /* output
        i = 1
        ++i = 2
        i++ = 2
        i2=3
        --i = 2
        i-- = 2
        i3=1
        */
        
        class Equaivalence{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1 == n2);
        		System.out.println(n1 != n2);
         }
        }
        
        class EqualsMethod{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1.equals(n2));
         }
        }
        
        class Value{
        	int i ;
        }
        class EqualsMethod2{
        	public static void main(String []args) {
        		Value v1 = new Value();
        		Value v2 = new Value();
        	 System.out.println(v1.equals(v2));
         }
        }
        
        class ShortCircuit{
        	static boolean test1(int val){
        		System.out.println("test1( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 1);
        	}
        	
        	static boolean test2(int val){
        		System.out.println("test2( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 2);
        	}
        	
        	static boolean test3(int val){
        		System.out.println("test3( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 3);
        	}
        	
        	
        	public static void main(String []args) {
        		
        		boolean b = test1(0) && test2(2) && test2(3);
        		System.out.println("expression is : "  + b );
        	}
        }

         

      2. 测试结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

第3章 操作符/3.9 直接变量

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 前缀标识进制
    1. 十六进制:0x或者0X开头,后面为0~9、a~f
    2. 八进制:0开头,后面为0~7
    3. 十进制:0~9开头
    4. 二进制:没有直接变量表示方法
  2. 后缀标识类型
    1. 大小写L:表示long
    2. 大小写F:表示float
    3. 大小写d:表示double

第3章 操作符/3.9 直接变量/3.9.1 指数记数法

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 举例
    1. 源代码:
      //: HelloDate.java
      import java.util.*;
      //import static net.mindview.until.Print.*;
      /** the first Thinking in java example program
        * display a string and today's date
        * @author wengyongsheng 
        * @version 4.0 
      */
      public class HelloDate{
      	/**
      	* @param args array of string arguments
      	*/
        public static void main(String []args) {
        System.out.println("Hello,It's: ");
        System.out.println(new Date());
      //  print("Hello,It's: ");
      }
      }
      
      class Tank{
      	 int level;
      }
      
      class Assignment{
      	public static void main(String []args) {
      		Tank t1 = new Tank();
      		Tank t2 = new Tank();
      		t1.level = 9;
      		t2.level = 47;
      		System.out.println("1:t1.level = " + t1.level + 
      		                   " t2.level = " + t2.level);
          t1 = t2;
          System.out.println("2:t1.level = " + t1.level + 
      		                   " t2.level = " + t2.level);
      		
      		t1.level = 27;
      		System.out.println("3:t1.level = " + t1.level + 
      		                   " t2.level = " + t2.level);                   		                   
      	}
      }
      
      class Letter{
      	 char c;
      }
      
      class PassObject{
      	static void f(Letter y){
      		y.c = 'z';
      	}
      	public static void main(String []args) {
      		Letter x = new Letter();
      		System.out.println("1:x.c= " + x.c);
      		x.c = 'a';
      		System.out.println("2:x.c= " + x.c);
      		f(x);
      		System.out.println("3:x.c= " + x.c);
      	}
      }
      
      class MathOps{
      	public static void main(String []args) {
      		Random rand = new Random(47);
      		int i , j , k;
      		j = rand.nextInt(100) + 1;
      		System.out.println("j = " + j);
      		k = rand.nextInt(100) + 1;
      		System.out.println("k = " + k);
      		i = j + k;
      		System.out.println("i = " + i);
      		
      		float u , v , w;
      		u = rand.nextFloat();
      		System.out.println("u = " + u);
      		v = rand.nextFloat() ;
      		System.out.println("v = " + v);
      		w = u + v;
      		System.out.println("w = " + w);
      	}
      }
      
      class AutoInc{
      	public static void main(String []args) {
      		int i = 1;
      		System.out.println("i = " + i);
      		System.out.println("++i = " + ++i);
      		System.out.println("i++ = " + i++);
      		System.out.println("i2 = " + i);
      		System.out.println("--i = " + --i);
      		System.out.println("i-- = " + i--);
      		System.out.println("i3 = " + i);
       }
      }
      /* output
      i = 1
      ++i = 2
      i++ = 2
      i2=3
      --i = 2
      i-- = 2
      i3=1
      */
      
      class Equaivalence{
      	public static void main(String []args) {
      		Integer n1 = new Integer(47);
      		Integer n2 = new Integer(47);
      		
      		System.out.println(n1 == n2);
      		System.out.println(n1 != n2);
       }
      }
      
      class EqualsMethod{
      	public static void main(String []args) {
      		Integer n1 = new Integer(47);
      		Integer n2 = new Integer(47);
      		
      		System.out.println(n1.equals(n2));
       }
      }
      
      class Value{
      	int i ;
      }
      class EqualsMethod2{
      	public static void main(String []args) {
      		Value v1 = new Value();
      		Value v2 = new Value();
      	 System.out.println(v1.equals(v2));
       }
      }
      
      class ShortCircuit{
      	static boolean test1(int val){
      		System.out.println("test1( " + val + " )");
      		System.out.println("result: "  + (val <1) );
      		return (val < 1);
      	}
      	
      	static boolean test2(int val){
      		System.out.println("test2( " + val + " )");
      		System.out.println("result: "  + (val <1) );
      		return (val < 2);
      	}
      	
      	static boolean test3(int val){
      		System.out.println("test3( " + val + " )");
      		System.out.println("result: "  + (val <1) );
      		return (val < 3);
      	}
      	
      	
      	public static void main(String []args) {
      		
      		boolean b = test1(0) && test2(2) && test2(3);
      		System.out.println("expression is : "  + b );
      	}
      }
      
      class Expinents{
      	public static void main(String []args) {
      		float expFloat = 1.21e-43f;
      		System.out.println("expFloat =  "  + expFloat );
      		double expDouble = 4.7e47d;
      		System.out.println("expDouble =  "  + expDouble );
       }
      }

       

    2. 结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符
  2. 注意:指数通常默认为double类型输入,如果这样编写一行代码:float f = le-43是会报错:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符,尾巴要加上加上“f”

第3章 操作符/3.10 按位操作符

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 概念:用来操作整数基本类型中的二进制位,对两个参数的对应位进行布尔代数运算
  2. 分类
    1. 按位与(&):两个都为1则为1
    2. 按位或(|):一个为1则为1
    3. 按位异或(易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符):两位相同为0,不同为1
    4. 按位非(~):0变成1,1变成0

第3章 操作符/3.11 移位操作符

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

    • 左移易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符:低位补0,移动多少位就是补0多少位
    • 右移易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符:高位补0,移动多少位就是砍掉末尾多少位 ;如果为正数则高位插入0,如果为负数则高位插入1
    • “无符号”右移易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符:无论正负高位都插入0
    • 举例:
      1. 源代码:
        //: HelloDate.java
        import java.util.*;
        //import static net.mindview.until.Print.*;
        /** the first Thinking in java example program
          * display a string and today's date
          * @author wengyongsheng 
          * @version 4.0 
        */
        public class HelloDate{
        	/**
        	* @param args array of string arguments
        	*/
          public static void main(String []args) {
          System.out.println("Hello,It's: ");
          System.out.println(new Date());
        //  print("Hello,It's: ");
        }
        }
        
        class Tank{
        	 int level;
        }
        
        class Assignment{
        	public static void main(String []args) {
        		Tank t1 = new Tank();
        		Tank t2 = new Tank();
        		t1.level = 9;
        		t2.level = 47;
        		System.out.println("1:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
            t1 = t2;
            System.out.println("2:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
        		
        		t1.level = 27;
        		System.out.println("3:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);                   		                   
        	}
        }
        
        class Letter{
        	 char c;
        }
        
        class PassObject{
        	static void f(Letter y){
        		y.c = 'z';
        	}
        	public static void main(String []args) {
        		Letter x = new Letter();
        		System.out.println("1:x.c= " + x.c);
        		x.c = 'a';
        		System.out.println("2:x.c= " + x.c);
        		f(x);
        		System.out.println("3:x.c= " + x.c);
        	}
        }
        
        class MathOps{
        	public static void main(String []args) {
        		Random rand = new Random(47);
        		int i , j , k;
        		j = rand.nextInt(100) + 1;
        		System.out.println("j = " + j);
        		k = rand.nextInt(100) + 1;
        		System.out.println("k = " + k);
        		i = j + k;
        		System.out.println("i = " + i);
        		
        		float u , v , w;
        		u = rand.nextFloat();
        		System.out.println("u = " + u);
        		v = rand.nextFloat() ;
        		System.out.println("v = " + v);
        		w = u + v;
        		System.out.println("w = " + w);
        	}
        }
        
        class AutoInc{
        	public static void main(String []args) {
        		int i = 1;
        		System.out.println("i = " + i);
        		System.out.println("++i = " + ++i);
        		System.out.println("i++ = " + i++);
        		System.out.println("i2 = " + i);
        		System.out.println("--i = " + --i);
        		System.out.println("i-- = " + i--);
        		System.out.println("i3 = " + i);
         }
        }
        /* output
        i = 1
        ++i = 2
        i++ = 2
        i2=3
        --i = 2
        i-- = 2
        i3=1
        */
        
        class Equaivalence{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1 == n2);
        		System.out.println(n1 != n2);
         }
        }
        
        class EqualsMethod{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1.equals(n2));
         }
        }
        
        class Value{
        	int i ;
        }
        class EqualsMethod2{
        	public static void main(String []args) {
        		Value v1 = new Value();
        		Value v2 = new Value();
        	 System.out.println(v1.equals(v2));
         }
        }
        
        class ShortCircuit{
        	static boolean test1(int val){
        		System.out.println("test1( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 1);
        	}
        	
        	static boolean test2(int val){
        		System.out.println("test2( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 2);
        	}
        	
        	static boolean test3(int val){
        		System.out.println("test3( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 3);
        	}
        	
        	
        	public static void main(String []args) {
        		
        		boolean b = test1(0) && test2(2) && test2(3);
        		System.out.println("expression is : "  + b );
        	}
        }
        
        class Expinents{
        	public static void main(String []args) {
        		float expFloat = 1.21e-43f;
        		System.out.println("expFloat =  "  + expFloat );
        		double expDouble = 4.7e47d;
        		System.out.println("expDouble =  "  + expDouble );
         }
        }
        
        class URShift{
        	public static void main(String []args) {
        		int initValue = 123;
        		int i = initValue;
        		System.out.println("i =  "  + Integer.toBinaryString(i));
        		i = (i<< 3);
        		System.out.println("i <<= 3  "  + Integer.toBinaryString(i));
        		i = initValue;
        		i = (i>> 3);
        		System.out.println("i >>= 3  "  + Integer.toBinaryString(i));
        		i = initValue;
        		i >>>= 2;
        		System.out.println("i >>>= 2  "  + Integer.toBinaryString(i));
         }
        }

         

      2. 输出结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

第3章 操作符/3.12 三元操作符if-else

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符


第3章 操作符/3.13 字符串操作符 + 和 +=

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 源代码:
    //: HelloDate.java
    import java.util.*;
    //import static net.mindview.until.Print.*;
    /** the first Thinking in java example program
      * display a string and today's date
      * @author wengyongsheng 
      * @version 4.0 
    */
    public class HelloDate{
    	/**
    	* @param args array of string arguments
    	*/
      public static void main(String []args) {
      System.out.println("Hello,It's: ");
      System.out.println(new Date());
    //  print("Hello,It's: ");
    }
    }
    
    class Tank{
    	 int level;
    }
    
    class Assignment{
    	public static void main(String []args) {
    		Tank t1 = new Tank();
    		Tank t2 = new Tank();
    		t1.level = 9;
    		t2.level = 47;
    		System.out.println("1:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);
        t1 = t2;
        System.out.println("2:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);
    		
    		t1.level = 27;
    		System.out.println("3:t1.level = " + t1.level + 
    		                   " t2.level = " + t2.level);                   		                   
    	}
    }
    
    class Letter{
    	 char c;
    }
    
    class PassObject{
    	static void f(Letter y){
    		y.c = 'z';
    	}
    	public static void main(String []args) {
    		Letter x = new Letter();
    		System.out.println("1:x.c= " + x.c);
    		x.c = 'a';
    		System.out.println("2:x.c= " + x.c);
    		f(x);
    		System.out.println("3:x.c= " + x.c);
    	}
    }
    
    class MathOps{
    	public static void main(String []args) {
    		Random rand = new Random(47);
    		int i , j , k;
    		j = rand.nextInt(100) + 1;
    		System.out.println("j = " + j);
    		k = rand.nextInt(100) + 1;
    		System.out.println("k = " + k);
    		i = j + k;
    		System.out.println("i = " + i);
    		
    		float u , v , w;
    		u = rand.nextFloat();
    		System.out.println("u = " + u);
    		v = rand.nextFloat() ;
    		System.out.println("v = " + v);
    		w = u + v;
    		System.out.println("w = " + w);
    	}
    }
    
    class AutoInc{
    	public static void main(String []args) {
    		int i = 1;
    		System.out.println("i = " + i);
    		System.out.println("++i = " + ++i);
    		System.out.println("i++ = " + i++);
    		System.out.println("i2 = " + i);
    		System.out.println("--i = " + --i);
    		System.out.println("i-- = " + i--);
    		System.out.println("i3 = " + i);
     }
    }
    /* output
    i = 1
    ++i = 2
    i++ = 2
    i2=3
    --i = 2
    i-- = 2
    i3=1
    */
    
    class Equaivalence{
    	public static void main(String []args) {
    		Integer n1 = new Integer(47);
    		Integer n2 = new Integer(47);
    		
    		System.out.println(n1 == n2);
    		System.out.println(n1 != n2);
     }
    }
    
    class EqualsMethod{
    	public static void main(String []args) {
    		Integer n1 = new Integer(47);
    		Integer n2 = new Integer(47);
    		
    		System.out.println(n1.equals(n2));
     }
    }
    
    class Value{
    	int i ;
    }
    class EqualsMethod2{
    	public static void main(String []args) {
    		Value v1 = new Value();
    		Value v2 = new Value();
    	 System.out.println(v1.equals(v2));
     }
    }
    
    class ShortCircuit{
    	static boolean test1(int val){
    		System.out.println("test1( " + val + " )");
    		System.out.println("result: "  + (val <1) );
    		return (val < 1);
    	}
    	
    	static boolean test2(int val){
    		System.out.println("test2( " + val + " )");
    		System.out.println("result: "  + (val <1) );
    		return (val < 2);
    	}
    	
    	static boolean test3(int val){
    		System.out.println("test3( " + val + " )");
    		System.out.println("result: "  + (val <1) );
    		return (val < 3);
    	}
    	
    	
    	public static void main(String []args) {
    		
    		boolean b = test1(0) && test2(2) && test2(3);
    		System.out.println("expression is : "  + b );
    	}
    }
    
    class Expinents{
    	public static void main(String []args) {
    		float expFloat = 1.21e-43f;
    		System.out.println("expFloat =  "  + expFloat );
    		double expDouble = 4.7e47d;
    		System.out.println("expDouble =  "  + expDouble );
     }
    }
    
    class URShift{
    	public static void main(String []args) {
    		int initValue = 123;
    		int i = initValue;
    		System.out.println("i =  "  + Integer.toBinaryString(i));
    		i = (i<< 3);
    		System.out.println("i <<= 3  "  + Integer.toBinaryString(i));
    		i = initValue;
    		i = (i>> 3);
    		System.out.println("i >>= 3  "  + Integer.toBinaryString(i));
    		i = initValue;
    		i >>>= 2;
    		System.out.println("i >>>= 2  "  + Integer.toBinaryString(i));
     }
    }
    
    class StringOperators{
    	public static void main(String []args) {
    	int i = 0, y =1 ,z = 2;
    	String s = "x,y,z ";
    	
    	System.out.println(s + i + y + z);
    	System.out.println(s + (i + y + z));
     }
    }

     

  2. 输出结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

第3章 操作符/3.14 使用操作符常犯的错误

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符


第3章 操作符/3.15 类型转换操作符

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

  1. 自动转换:编译器自动完成,比如把整数自动转换为浮点型
  2. 强制转换:显式转换,将要转换的类型置于小括号内
  1. 基本数据类型可以转换为别的基本数据类型,但是不包括boolean
  2. "类"数据类型不允许转换,但是同一类族的类型之间可以转换

 


第3章 操作符/3.15 类型转换操作符/3.15.1 截尾和舍入

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

 

    • 使用场合:主要是针对“窄化转换”,将一个大类型转换为小类型,比如将一个浮点型转换为整型
    • 举例:无四舍五入
      1. 源代码:
        //: HelloDate.java
        import java.util.*;
        //import static net.mindview.until.Print.*;
        /** the first Thinking in java example program
          * display a string and today's date
          * @author wengyongsheng 
          * @version 4.0 
        */
        public class HelloDate{
        	/**
        	* @param args array of string arguments
        	*/
          public static void main(String []args) {
          System.out.println("Hello,It's: ");
          System.out.println(new Date());
        //  print("Hello,It's: ");
        }
        }
        
        class Tank{
        	 int level;
        }
        
        class Assignment{
        	public static void main(String []args) {
        		Tank t1 = new Tank();
        		Tank t2 = new Tank();
        		t1.level = 9;
        		t2.level = 47;
        		System.out.println("1:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
            t1 = t2;
            System.out.println("2:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
        		
        		t1.level = 27;
        		System.out.println("3:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);                   		                   
        	}
        }
        
        class Letter{
        	 char c;
        }
        
        class PassObject{
        	static void f(Letter y){
        		y.c = 'z';
        	}
        	public static void main(String []args) {
        		Letter x = new Letter();
        		System.out.println("1:x.c= " + x.c);
        		x.c = 'a';
        		System.out.println("2:x.c= " + x.c);
        		f(x);
        		System.out.println("3:x.c= " + x.c);
        	}
        }
        
        class MathOps{
        	public static void main(String []args) {
        		Random rand = new Random(47);
        		int i , j , k;
        		j = rand.nextInt(100) + 1;
        		System.out.println("j = " + j);
        		k = rand.nextInt(100) + 1;
        		System.out.println("k = " + k);
        		i = j + k;
        		System.out.println("i = " + i);
        		
        		float u , v , w;
        		u = rand.nextFloat();
        		System.out.println("u = " + u);
        		v = rand.nextFloat() ;
        		System.out.println("v = " + v);
        		w = u + v;
        		System.out.println("w = " + w);
        	}
        }
        
        class AutoInc{
        	public static void main(String []args) {
        		int i = 1;
        		System.out.println("i = " + i);
        		System.out.println("++i = " + ++i);
        		System.out.println("i++ = " + i++);
        		System.out.println("i2 = " + i);
        		System.out.println("--i = " + --i);
        		System.out.println("i-- = " + i--);
        		System.out.println("i3 = " + i);
         }
        }
        /* output
        i = 1
        ++i = 2
        i++ = 2
        i2=3
        --i = 2
        i-- = 2
        i3=1
        */
        
        class Equaivalence{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1 == n2);
        		System.out.println(n1 != n2);
         }
        }
        
        class EqualsMethod{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1.equals(n2));
         }
        }
        
        class Value{
        	int i ;
        }
        class EqualsMethod2{
        	public static void main(String []args) {
        		Value v1 = new Value();
        		Value v2 = new Value();
        	 System.out.println(v1.equals(v2));
         }
        }
        
        class ShortCircuit{
        	static boolean test1(int val){
        		System.out.println("test1( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 1);
        	}
        	
        	static boolean test2(int val){
        		System.out.println("test2( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 2);
        	}
        	
        	static boolean test3(int val){
        		System.out.println("test3( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 3);
        	}
        	
        	
        	public static void main(String []args) {
        		
        		boolean b = test1(0) && test2(2) && test2(3);
        		System.out.println("expression is : "  + b );
        	}
        }
        
        class Expinents{
        	public static void main(String []args) {
        		float expFloat = 1.21e-43f;
        		System.out.println("expFloat =  "  + expFloat );
        		double expDouble = 4.7e47d;
        		System.out.println("expDouble =  "  + expDouble );
         }
        }
        
        class URShift{
        	public static void main(String []args) {
        		int initValue = 123;
        		int i = initValue;
        		System.out.println("i =  "  + Integer.toBinaryString(i));
        		i = (i<< 3);
        		System.out.println("i <<= 3  "  + Integer.toBinaryString(i));
        		i = initValue;
        		i = (i>> 3);
        		System.out.println("i >>= 3  "  + Integer.toBinaryString(i));
        		i = initValue;
        		i >>>= 2;
        		System.out.println("i >>>= 2  "  + Integer.toBinaryString(i));
         }
        }
        
        class StringOperators{
        	public static void main(String []args) {
        	int i = 0, y =1 ,z = 2;
        	String s = "x,y,z ";
        	
        	System.out.println(s + i + y + z);
        	System.out.println(s + (i + y + z));
         }
        }
        
        class CastringNumbers{
        	public static void main(String []args) {
        		
        	double above = 0.7,below = 0.4;
        	float  fabove = 0.7f,fbelow = 0.4f;
        	
        	System.out.println("above = " + (int)above);
        	System.out.println("below = " + (int)below);
        	System.out.println("fabove = " + (int)fabove);
        	System.out.println("fbelow = " + (int)fbelow);
        	
         }
        }
      2. 输出结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符,没有四舍五入,都是截断为0了
    • 举例:四舍五入
      1. 源代码:
        //: HelloDate.java
        import java.util.*;
        //import static net.mindview.until.Print.*;
        /** the first Thinking in java example program
          * display a string and today's date
          * @author wengyongsheng 
          * @version 4.0 
        */
        public class HelloDate{
        	/**
        	* @param args array of string arguments
        	*/
          public static void main(String []args) {
          System.out.println("Hello,It's: ");
          System.out.println(new Date());
        //  print("Hello,It's: ");
        }
        }
        
        class Tank{
        	 int level;
        }
        
        class Assignment{
        	public static void main(String []args) {
        		Tank t1 = new Tank();
        		Tank t2 = new Tank();
        		t1.level = 9;
        		t2.level = 47;
        		System.out.println("1:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
            t1 = t2;
            System.out.println("2:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);
        		
        		t1.level = 27;
        		System.out.println("3:t1.level = " + t1.level + 
        		                   " t2.level = " + t2.level);                   		                   
        	}
        }
        
        class Letter{
        	 char c;
        }
        
        class PassObject{
        	static void f(Letter y){
        		y.c = 'z';
        	}
        	public static void main(String []args) {
        		Letter x = new Letter();
        		System.out.println("1:x.c= " + x.c);
        		x.c = 'a';
        		System.out.println("2:x.c= " + x.c);
        		f(x);
        		System.out.println("3:x.c= " + x.c);
        	}
        }
        
        class MathOps{
        	public static void main(String []args) {
        		Random rand = new Random(47);
        		int i , j , k;
        		j = rand.nextInt(100) + 1;
        		System.out.println("j = " + j);
        		k = rand.nextInt(100) + 1;
        		System.out.println("k = " + k);
        		i = j + k;
        		System.out.println("i = " + i);
        		
        		float u , v , w;
        		u = rand.nextFloat();
        		System.out.println("u = " + u);
        		v = rand.nextFloat() ;
        		System.out.println("v = " + v);
        		w = u + v;
        		System.out.println("w = " + w);
        	}
        }
        
        class AutoInc{
        	public static void main(String []args) {
        		int i = 1;
        		System.out.println("i = " + i);
        		System.out.println("++i = " + ++i);
        		System.out.println("i++ = " + i++);
        		System.out.println("i2 = " + i);
        		System.out.println("--i = " + --i);
        		System.out.println("i-- = " + i--);
        		System.out.println("i3 = " + i);
         }
        }
        /* output
        i = 1
        ++i = 2
        i++ = 2
        i2=3
        --i = 2
        i-- = 2
        i3=1
        */
        
        class Equaivalence{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1 == n2);
        		System.out.println(n1 != n2);
         }
        }
        
        class EqualsMethod{
        	public static void main(String []args) {
        		Integer n1 = new Integer(47);
        		Integer n2 = new Integer(47);
        		
        		System.out.println(n1.equals(n2));
         }
        }
        
        class Value{
        	int i ;
        }
        class EqualsMethod2{
        	public static void main(String []args) {
        		Value v1 = new Value();
        		Value v2 = new Value();
        	 System.out.println(v1.equals(v2));
         }
        }
        
        class ShortCircuit{
        	static boolean test1(int val){
        		System.out.println("test1( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 1);
        	}
        	
        	static boolean test2(int val){
        		System.out.println("test2( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 2);
        	}
        	
        	static boolean test3(int val){
        		System.out.println("test3( " + val + " )");
        		System.out.println("result: "  + (val <1) );
        		return (val < 3);
        	}
        	
        	
        	public static void main(String []args) {
        		
        		boolean b = test1(0) && test2(2) && test2(3);
        		System.out.println("expression is : "  + b );
        	}
        }
        
        class Expinents{
        	public static void main(String []args) {
        		float expFloat = 1.21e-43f;
        		System.out.println("expFloat =  "  + expFloat );
        		double expDouble = 4.7e47d;
        		System.out.println("expDouble =  "  + expDouble );
         }
        }
        
        class URShift{
        	public static void main(String []args) {
        		int initValue = 123;
        		int i = initValue;
        		System.out.println("i =  "  + Integer.toBinaryString(i));
        		i = (i<< 3);
        		System.out.println("i <<= 3  "  + Integer.toBinaryString(i));
        		i = initValue;
        		i = (i>> 3);
        		System.out.println("i >>= 3  "  + Integer.toBinaryString(i));
        		i = initValue;
        		i >>>= 2;
        		System.out.println("i >>>= 2  "  + Integer.toBinaryString(i));
         }
        }
        
        class StringOperators{
        	public static void main(String []args) {
        	int i = 0, y =1 ,z = 2;
        	String s = "x,y,z ";
        	
        	System.out.println(s + i + y + z);
        	System.out.println(s + (i + y + z));
         }
        }
        
        class CastringNumbers{
        	public static void main(String []args) {
        		
        	double above = 0.7,below = 0.4;
        	float  fabove = 0.7f,fbelow = 0.4f;
        	
        	System.out.println("above = " + (int)above);
        	System.out.println("below = " + (int)below);
        	System.out.println("fabove = " + (int)fabove);
        	System.out.println("fbelow = " + (int)fbelow);
        	
         }
        }
        
        class RoundNumbers{
        	public static void main(String []args) {
        		
        	double above = 0.7,below = 0.4;
        	float  fabove = 0.7f,fbelow = 0.4f;
        	
        	System.out.println("above = " + Math.round(above));
        	System.out.println("below = " + Math.round(below));
        	System.out.println("fabove = " + Math.round(fabove));
        	System.out.println("fbelow = " + Math.round(fbelow));
        	
         }
        }

         

      2. 输出结果:易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

第3章 操作符/3.15 类型转换操作符/3.15.2 提升

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符


第3章 操作符/3.16 Java没有sizeof

标签: 作者:易学笔记  更多资料请联系微信或QQ:1776565180

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符

易学笔记--从0开始学JAVA(个人纯手工笔记共享 免费!免费!免费!)--第3章 操作符