Self-learning java-operator

Source: Internet
Author: User

Problems with 1.byte values:

BYTE b1=127;

byte b2= (byte) 128; -128

byte b3= (byte) 129; -127

byte b4= (byte) 130; -126


The range of byte: 128 ~ 127,

128:10 million

-128:10000000 (here 1 is both the sign bit and the value bit).



2. Default conversion of data type conversions:

As long as the participating operation is promoted to int.


Byte, short, char--INT--long--float--double,

Long:8 bytes, float:4 bytes.


Their underlying storage structure is different, and the floating-point numbers turn into fractional binary operations,

17.625 converted into binary 10001.101,

The integer part, divided by 2, until the quotient is 0, the remainder is reversed,

The decimal part is multiplied by 2 until the multiply is 0 and the rounding order is taken.


Move 10001.101 to the right until the decimal sign is only 1 digits, 1.0001101*2^4, because the four-bit is shifted to the right.


The range of data represented by float is larger than the range of long,

Long,2^63-1,

float,3.4*10^38 > 2*10^38 > 2*8^38 > 2*2^3^38 = 2*2^114 > 2^63-1.


The character char in the Java language can store a Chinese character because the characters in the Java language account for two bytes,

Java is based on Unicode encoding.



3. Operators:

An operator is a symbol that operates on constants and variables.


Classification, arithmetic operators, assignment operators, comparison operators, logical operators, bitwise operators, and trinocular operators.


Integers can be divided into integers, and to get decimals, you only need to change any of the data in the operation into floating-point numbers.

x*1.0/y, it does not change the value, but also can get the floating point number.


The use of the + + 、--operator,

Used alone, in the same way as before and after the operand,

Participate in the operation, put in before the operand, the first self-reduction, and then participate in the operation, put in the operand, first participate in the operation, and then self-increment.

int x=4; int y= (x + +) + (++x) + (X*10); 4+6+60=70.


String connector (+),

System.out.println ("Hello" + ' a ' + 1); Helloa1

System.out.println (' A ' +1+ "Hello"); 98hello


The extended assignment operator actually implies a forced type conversion, s+=1; is not equivalent to s=s+1;

Instead, it is equivalent to s= (the data type of s) (s+1);.


& Before and after the number, do bit arithmetic, before and after is the Boolean value, does the logical operation, other similar.


& Logic with, | logic or, ^ logical XOR,! Logical Non.

&& compared to & with short-circuit action, the left is false, the right is not executed, so program execution efficiency is higher than &,| | Same as |.


Bitwise operator,& (with 0 0), | (1 1), ^ (same 0 different 1), ~ (bitwise reverse),<<, >>, >>>.


Swaps the values of two variables,

The use of a different or realization, a=a^b; B=a^b; A=a^b; ,

With the addition of variables to achieve, a=a+b; B=a-b; A=a-b; ,

A word to fix, b= (a+b)-(a=b);.


Displacement operator,

<< left, left highest bit discarded, right 0,

>> right SHIFT, the highest bit is 0, the left is 0, the highest bit is 1, the left is 1,

>>> unsigned Right shift, whether the top bit is 0 or 1 on the left, and 0 on the left.


<<, multiply << left data by 2 to move the power, >>, divide >> left data by 2 to move power,

The most efficient way of 2*16, namely 2<<4.


Monocular operator (~), binocular operator (3+4),

The trinocular operator, the comparison expression? Expression 1: Expression 2, returns True, executes expression 1, returns false, executes expression 2.

Three number comparison size, one step to fix,

int max= (A>B)? (a>c) A:C):((b>c) b:c); ,

Boolean flag= (m==n)? True:false; Compares two numbers for the same.



4. Keyboard entry:

Guide package, import Java.util.Scanner;

Create keyboard Entry object, Scanner sc=new Scanner (system.in);

Get data by object, int x=sc.nextint ();.



5. Process Control Statements:

Process Control statements are divided into 3 categories, sequential structure, selection structure, and cyclic structure.



This article from "Xiaozhuan 2016" blog, declined reprint!

Self-learning java-operator

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.