JAVA Arithmetic Operators, Relational operators, bitwise operators, and java Arithmetic Operators

Source: Internet
Author: User

JAVA Arithmetic Operators, Relational operators, bitwise operators, and java Arithmetic Operators

Arithmetic Operators

1. java Arithmetic Operators include + (plus),-(minus), * (multiplication),/(Division), and % (remainder ), the implicit conversion principle in the operation process is the same as that in the C language;
2. Forced conversion is required for converting high-level data to low-level data;

Relational operators

1. java Relational operators include >,<>=, <=, =, and ,! =, The use rules are the same as those in the C language, and there is also a short circuit principle in complex relational computing statements;
2. The output result of the java logic operation can only be false or true, and the result is of the boollean type. This is different from the C language!

Public class Operator {public static void main (String args []) {System. out. println ("10> 5:" + (10> 5); System. out. the result of println ("10> = 5 is:" + (10> = 5); System. out. println ("10 <5 Result:" + (10 <5); System. out. println ("10 <= 5:" + (10 <= 5); System. out. println ("10 = 5:" + (10 = 5); System. out. println ("10! = 5: "+ (10! = 5 ));}}

Bitwise operators

1. java bitwise operators include: & (and) | (OR )~ (Not) ^ (exclusive or );

2. Operators that contain bitwise operators convert data into binary values during operations;

3;

|: Convert the two data for calculation into binary data, and then calculate the corresponding BIT data. One of them is 1, which is 1;

^: Convert the two data for calculation into binary data, and then calculate the data on the corresponding bit. The difference is 1, and the same value is 0;

~ : Convert the two data for calculation into binary data, and then calculate the corresponding bit of data, each bit is reversed;

public class ByteOperator{    public static void main(String args[])    {        System.out.println("0 and 0\t"+(0&0));        System.out.println("0 and 1\t"+(0&1));        System.out.println("1 and 0\t"+(1&0));        System.out.println("1 and 1\t"+(1&1));        System.out.println("-------------------");        System.out.println("0 or 0\t"+(0|0));        System.out.println("0 or 1\t"+(0|1));        System.out.println("1 or 0\t"+(1|0));        System.out.println("1 or 1\t"+(1|1));        System.out.println("-------------------");        System.out.println("0 XOR 0\t"+(0^0));        System.out.println("0 XOR 1\t"+(0^1));        System.out.println("1 XOR 0\t"+(1^0));        System.out.println("1 XOR 1\t"+(1^1));        System.out.println("-------------------");        System.out.println("~0\t"+(~0));        System.out.println("~1\t"+(~1));    }}

 

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.