In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what Java operators have and how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this Java operator and how to use the article, let's take a look.
1. Arithmetic operator meaning + summation-subtraction * product / quotient% remainder (module) + + self-plus-self-minus-1. + operator 1.1 + in front of the variable
When + + appears in front of a variable, it will first add one to itself and do the assignment operation.
Int x = 100; int y = + + x; step: ② ① System.out.println (x); / / 101System.out.println (y); / / 1011.2 + + after the variable
When + + appears in a variable, it will first do the assignment operation, and then add 1 to it.
Int m = 20; int n = masks; step: ① ② System.out.println (n); / / 20 System.out.println (m); / / 211.3 specifically, in print, int c = 90; System.out.println (C++); / / pass, where this "pass" has an invisible assignment. 90 / / disassemble the above code / / int temp = clockwise; / / System.out.println (temp); int d = 80; System.out.println (+ + d); / / 81 / / disassemble / / int temp2 = + + d; / / System.out.println (temp2) 2. Operator (example same as + operator) 2.1-- before variable
When-appears before the variable, it will first subtract one and do the assignment operation.
2.2-after the variable
When-appears in the variable, it will first do the assignment operation, and then subtract 1.
Note:
For the + operator:
1. It can appear before or after a variable.
two。 Whether it appears before or after the variable, after the + + execution ends, the value of the variable must be incremented by 1.
Second, the meaning of relational operator operator > greater than > = greater than or equal to yearly +); / / false / / through this test: the expression x > yawning + has been executed. System.out.println (y); / / 12 / / Test short circuit and & & int m = 10; int n = 11; / / when using short circuit and & &, when the expression on the left is false, the expression on the right does not execute / / this phenomenon is called short circuit. System.out.println (m > n & m > n +); System.out.println (n); / / 111.2 what is the short circuit phenomenon?
The expression on the right is not executed, which is called short circuit.
1.3 when to use & &, when to use &?
In terms of efficiency, & is more efficient than &.
Because logic and & regardless of the result of the first expression, the second expression is bound to execute.
In future development, short circuit and & & and logic and need to coexist at the same time.
In most cases, it is recommended to use short circuit and & & choose logic and & only if you need both left and right expression execution.
two。 Short circuit or | |
With short circuit and similar
Int x = 10; int y = 11; System.out.println (x
< y | x >); / / teur / / the result of this test is that the expression x > y has executed. System.out.println (y); / / 12 / / Test short circuit or | | int m = 10; int n = 11; / / when using short circuit or | |, when the expression on the left is true, the expression on the right does not execute / / this phenomenon is called short circuit. System.out.println (m)
< n || m >System.out.println (n); / / 113. Summary
When using short circuit and & &, when the expression on the left is false, the expression on the right does not execute
When using short circuit or | | when the expression on the left turns out to be true, the expression on the right does not execute
Note: both sides of the logical operator are required to be of Boolean type, and the final result of the operation is also Boolean.
Fourth, the meaning of assignment operator operator = assignment + = addition, etc. (add / add this number on the original basis)-= subtraction (same) * = multiplication (same) / division (same)% = module (same)
Note: except for the first assignment operator, all extend the assignment operator!
An important grammatical mechanism:
When using the extended assignment operator, the result type is never changed.
Int m = 10; m + = 10; similar to m = m + 1 * *-> Note is similar!! Is it actually different: I = I + 10; and I + = 10; is it the same? Byte I = 10; I + = 10-> No error is reported. In fact, x + = 1 is equivalent to: X = (byte) (x + 1); I = I + 10 -> error: incompatible types: there may be a loss when converting from int to byte. The compiler detects that x + 1 is an int type, and the int type cannot be assigned directly to the variable x of type byte! For details, see the sixth rule to be followed when converting Java types: I + = 190; / / I = (byte) (I + 190); System.out.println (I); / / 44 (of course, precision is automatically lost. ) 5. Conditional operator 1. Syntax format: (ternary operator. ) Boolean expression? Expression 1: expression 22. What is the principle of execution?
When the result of a Boolean expression is true, the execution result of expression 1 is the result of the entire expression.
When the result of a Boolean expression is false, the execution result of expression 2 is the result of the entire expression.
It's funny:
Char a = true? "male": "female"; string A1 = true? "male": "female"; both of the above are wrong. / / below you can String s = ""; s + = true? The string concatenation operator (+) 1. + operator has two functions in the java language.
Action 1: summation
Function 2: string concatenation
two。 When do you ask for peace? When will the strings be concatenated?
Sum when both sides of the + operator are numeric types.
When the "either side" of the + operator is a string type, the + performs a string concatenation.
3. It is important to remember that the result after the string is concatenated is still a string. Int a = 100; int b = 200; / / there are numbers on both sides of the + here, so the addition operation int c = a + b; System.out.println (a + "+" + b + "=" + a + b); / / 100200 System.out.println (a + "+" + b + "=" + (a + b)); / 100cycles 20000300
Note: follow the order of "from left to right". (unless additional parentheses are added, parentheses have a high priority)
This is the end of the article on "what Java operators are and how to use them". Thank you for reading! I believe you all have a certain understanding of "what Java operators are and how to use them". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.