New usages and new realizations of Java operators

Source: Internet
Author: User

 Public classDemo1 { Public Static voidMain (string[] args) {Booleant =false|true;        System.out.println (t); T|=false;        System.out.println (t); T= t&false;        System.out.println (t); T&=false;        System.out.println (t); T= t^true;        System.out.println (t); T^=true;    System.out.println (t); }

^ Xor operator

True ^ false = True false ^ true = False ^ false = False true ^ true = False

As long as two conditions are true or false at the same time, the result is false.

If there is a scene now, the company needs two programmers, because it takes a man and a woman to take into account the enthusiasm of the work.

Mister in the final audit must probably be like this

if (! (x== male ^y== | | x== (female ^y== )) {  Direct pass}
Java use XOR operator ^ for two integers to be exchanged
Scanner in=New  Scanner (system.in); int A=in.nextint (); int b=in.nextint (); A=a^B; B=b^A; A=a^B; System.out.println (A+ "" +b);

Many paired occurrences of numbers are saved in the disk file, noting that the paired numbers are not necessarily contiguous, such as 2, 3, 4, 3, 4, 2 ...., because unexpectedly a number disappears, how quickly find out which number disappears

Since a number disappears, there must be a number that appears once and the other numbers appear even several times. It is not necessary to use the search to do, using the two characteristics of the XOR operation--1. Oneself or the result is 0,2. XOR or Satisfaction
Exchange law.

 Public Static int findlost (int  a[]) {         int result=0;           for (int i=0;i<a.length;i++) {             result^=a[i];         }          return

New usages and new realizations of Java operators

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.