In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this "Java operator application case analysis" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Java operator application case analysis" article.
1. Arithmetic operator 1. Brief introduction
In Java, the arithmetic operators +, -, *, /, and% are used to represent addition, subtraction, multiplication and division, respectively.
two。 Apply +
There are three kinds of + in java: 1. Normal operation. 2. Use it as a positive or negative. 3. As a connector (when data of any data type is connected to a string, that + sign is the connector)
Example:
Package com;public class liu {public static void main (String [] args) {/ / example 1: as a normal operation int c = 1; int d = 2; int e = c + d; System.out.println (e) / / the final result is 3 / / example 2: two variables an and b are known as connectors / / with values of 1 and 2, respectively. Output a + b = 3,1 + 2 = 3 int a = 1; int b = 2; System.out.println (a + "+" + b + "=" + (a + b)) / / the console displays the result: a + b = 3. / / notice that "+" and "=" are used as strings at this time, while (a + b) is calculated. }-
There are two kinds of + in java: 1. Normal operation. 2. Use it as a positive or negative.
Example:
Package com;public class liu {public static void main (String [] args) {int a = 1; int b = 3; int c = bmura; System.out.println (c); / / result: 2. } *
Example:
Package com;public class liu {public static void main (String [] args) {int I = 4; int j = 2; int a = iambij; System.out.println (a); / / 8}} /
When the two numbers involved in the operation are both integers, the result is an integer and vice versa.
Example:
Package com;public class liu {public static void main (String [] args) {/ / instance 1: as integer operation int I = 4; int j = 2; int a = I / j; System.out.println (a); / / 2 / / instance 2: as floating point operation int I = 5 Double j = 2; double a = I / j; System.out.println (a); / / 2.5}}%
The remainder of an integer (sometimes called modulo) is represented by%.
Package com;public class liu {public static void main (String [] args) {int I = 2; int j = 3; System.out.println (I% j); / / 0 int a = 4; int b = 2; System.out.println (a% b) / / 2} 2. The self-increasing and self-decreasing operator + +
Use alone: the result is the same regardless of whether + + is before or after, as detailed in example 1.
Participate in the operation: + + first: add 1 by yourself, and then participate in the operation. For more information, please see example 2: participate in the operation first, and then add 1 by yourself. For more information, see example 3.
Example:
Package com;public class liu {public static void main (String [] args) {/ / instance 1: operate separately. Int I = 1; iDiffect; / / I = I + 1 + + I; System.out.println (I); / / the result is equal to 2. / / instance 2 is the previous one. Int I = 1; int j = + + I; System.out.println (j); / / 2 System.out.println (I); / / 2 / / instance 3. Int I = 1; int j = iTunes; System.out.println (j); / / 1 System.out.println (I); / / 2}}-
Used alone: whether before or after, the result is the same, as detailed in example 1.
Participate in the operation:-before: subtract 1 by yourself, and then participate in the operation. For more information, please see example 2: participate in the operation first, and then subtract 1 by yourself. For more information, please see example 3.
Package com;public class liu {public static void main (String [] args) {/ / instance 1: operate separately. Int I = 2; I Murray; / / I = I-1-- I; System.out.println (I); / / the results are all equal to 1. / / example 2 is the previous one. Int I = 1; int j =-- I; System.out.println (j); / / 1 System.out.println (I); / / 1 / / instance 3 System.out.println Murray-later. Int I = 1; int j = iMurray; System.out.println (j); / / 2 System.out.println (I); / / 1}} III. Assignment operator
You can use binary operators in assignments in a very simple form: X + = 4 is equivalent to x = x + 4.
Common assignment operators are: =, + =,-=, * =, / =,% =.
Take + = as an example:
Package com;public class liu {public static void main (String [] args) {int I = 1; I + = 2; / / I = I + 2 System.out.println (I); / / output result 3 byte b = 1; b + = 2 / / b = (byte) (b + 2) System.out.println (b);}} IV. Relational operator
The result of the relational operator must be data of type boolean, that is to say, either true or false
Common relational operators: >, =, j); / / true System.out.println (I
< j);//false System.out.println(i >= j) / / true System.out.println (I > (right shift operation), > (unsigned right shift).
Example:
Package com;public class Demo01 {public static void main (String [] args) {System.out.println (3 & 2); / / 2 System.out.println (3 | 2); / / 3 System.out.println (3 ^ 2); / / 1 System.out.println (~ 3); / /-4 System.out.println (3 > > 2) / / 0 System.out.println (3 > > 2); / 0 System.out.println (- 3 > > 2); / /-1 System.out.println (- 3 > 2);}}
What is the difference between > > and >?
> >: if the data is negative, the leftmost symbol bit is 1. After moving to the right, the left side should be added by 1.
If the data is positive, the leftmost symbol bit is 0. After moving to the right, the left side should be filled with 0.
>
7. Ternary operator
Format: conditional expression? Expression 1: expression 2; equivalent to x > y? X: y
The result of a conditional expression must be of type boolean
Perform the process:
If the conditional expression is true, expression 1 is executed, not expression 2
If the conditional expression is false, expression 2 is executed, not expression 1
Example:
Package com;public class Demo02 {public static void main (String [] args) {/ / get the larger values of two numbers int I = 2; int j = 3; / / first: int max = I > j? I: J; System.out.println (max); / / 3 / / the second kind: System.out.println (I > j? I: J); / / since expression 1 and expression 2 will get a result, if passed to a variable to receive, the data type of that variable should match the data type of the result of expression 1 and expression 2. / / floating point: double d = 3 > 2? 1: 2; System.out.println (d); / / output: 1.0 / / character type: char C1 = 3 > 2.97 char 98; System.out.println (C1) / / output: a}} the above is the content of this article on "Application example Analysis of various operators of Java". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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.