问答详情
源自:3-3 Java中的赋值运算符

最后一项输出错误

30
40
30
300
30
10


提问者:斐珺孜 2018-05-09 22:04

个回答

  • 代码写的比较菜
    2018-05-09 22:42:17

    位与运算符(&)

    运算规则:两个数都转为二进制,然后从高位开始比较,如果两个数都为1则为1,否则为0。

    比如:10&30.

    10转换成二进制就是01010,30转换成二进制就是11110。从高位开始比较得到,得到01010,即10.


  • 斐珺孜
    2018-05-09 22:08:16

    public class HelloWorld{
        public static void main(String[] args) {
        	   int one = 10 ;
               int two = 20 ;
               int three = 0 ;        
               three =one+two;        
               System.out.println(three);        
               //three=0;        
               three+=one;        
               System.out.println(three);        
               //three=0;        
               three-=one;        
               System.out.println(three);                
               //three=0;        
               three*=one;        
               System.out.println(three);                
               //three=0;        
               three/=one;        
               System.out.println(three);                
               //three=0;        
               three &=one;        
               System.out.println(three);                   	
               }
      }

    厉害的一个一个敲空格,这排版跟shi一样

  • 斐珺孜
    2018-05-09 22:05:27

    public class HelloWorld{    public static void main(String[] args) {	   int one = 10 ;        int two = 20 ;        int three = 0 ;        three =one+two;        System.out.println(three);        //three=0;        three+=one;        System.out.println(three);        //three=0;        three-=one;        System.out.println(three);                //three=0;        three*=one;        System.out.println(three);                //three=0;        three/=one;        System.out.println(three);                //three=0;        three &=one;        System.out.println(three);                   	}}

    代码如下