6.Java logical operators and bitwise operators

Source: Internet
Author: User

A. There are three logical operator logical operators, namely "non", "and", "or", with "!", "&&", "| | |", respectively. Said. which
    • Non-op (!) Indicates negation, such as:!true equals false,!false equals True,!2 equals false,!0 equals True.
    • and arithmetic (&&) before and after two conditions are true, returns True, otherwise false.
    • Or Operation (| |) Before and after two conditions there is a true, return to False, all false.

public class data10{
public static void Main (string[] args) {
int a=10;
int b=21;
int c=10;
System.out.println ("Say A>b, right?") "+! (a>b));
System.out.println ("Think A>b and A<b, right?" "+ ((a>b) && (a<b)));
System.out.println ("Think A>b and A<b, right?" "+ ((a>=b) | | (a==b)));
System.out.println ("Think A>b and A=c, right?" "+ ((a<b) | | (a==c)));
}
}

Operation Result:
Say A>b, right? True
Think both A>b and A<b, right? False
Think both A>b and A<b, right? False
Think both A>b and A=c, right? True two. The bitwise operator bit operator is primarily for binary, and it includes: "and", "Non", "or", "XOR", respectively "&", "~", "| "," ^ ". which
    • The bitwise of the two operands with the operation (&) is 1, the result is 1, otherwise the result is 0.
    • The bitwise of the operand of the non-operation (~) is 0, the result is 1, and if 1, the result is 0.
    • or Operation (|) As long as two operands have a bit of 1, the result is 1, or 0.
    • The phase of the two operand of an XOR operation (^) has a simultaneous result of 0, and the result is 1.

public class data13{
public static void Main (string[] args) {
int a=129;
int b=128;
int x=15;
int y=2;
System.out.println ("A and B" with the result is: "+ (a&b));
System.out.println ("A and B" or the result is: "+ (a|b));
System.out.println ("X and y xor result is:" + (x^y));
}
}

Operation Result:
A and B with the result is: 128
A and B or the result is: 129
The result of X and Y xor is: 13

6.Java logical operators and bitwise 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.