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--
In this article, the editor introduces in detail "how to use the five operators of Java". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use the five operators of Java" can help you solve your doubts.
1. Arithmetic operator
The symbols of arithmetic operators are usually: addition (+), subtraction (-), multiplication (*), division (/), remainder (%), self-increment (+), and self-subtraction (- -).
If you divide a variable of type int and a variable of type int, the result is still of type int.
Using the constant of double type and the constant of int type as division, you will get the result of double type; you can get the double type by using forced type double conversion
System.out.println (7 / 2); / / 3.0System.out.println ((double) (7 / 2)); / / 3.0System.out.println ((double) 7 / 2); / / 3.5
Since there is division, then for the special number of division 0, how does the Java program deal with it? are they all abnormal errors? We can give it a try.
/ / generate an exception: java.lang.ArithmeticException: / by zero int i = 123 / 0; System.out.println (I); / generate an exception: java.lang.ArithmeticException: / by zero int j = 0 / 0; System.out.println (j); double k = 123.45 / 2; System.out.println (k); / / 61.725 double x = 123.45 / 0; System.out.println (x) / / Infinity (positive infinity) double y =-0 / 0; System.out.println (y); / /-Infinity (negative infinity) double m = 123.45 / 0; System.out.println (m); / / NaN (Not a number is not a number) double n =-0.0 / 0; System.out.println (n); / / NaN (Not a number is not a number) float x = 123.45F / 0; System.out.println (x) / / Infinity (positive infinity) float y =-123.45F / 0; System.out.println (y); / /-Infinity (negative infinity) float m = 0.0F / 0; System.out.println (m); / / NaN (Not a number is not a number) float n =-0.0F / 0; System.out.println (n) / / NaN (Not a number is not a number) / / an exception occurs: java.lang.ArithmeticException: / by zero int x = 11% 0; System.out.println (x); double y = 11.0% 0; System.out.println (y); / / NaN
Self-increasing operator
Use the self-increment operator alone: whether + + is placed before or after a variable that needs to be self-incremented, it will increase the value of the variable by 1 after the operation.
Do not use the self-increment operator: int j = iincrement operator; / / I: 3 j: 2 (first assign the value of I to j, then I do self-increment (first assignment and then self-increment); int j = + + I; / / I: 3 j: 3 (self-increment first, then assign the value of I (self-increment) to j (self-increment and then assign)
An exercise is attached here:
Int I = 2; int j = 3; j = iTunes + + + i+i*6
What is the last j? (result: 30)
2. Assignment operator
Assignment operators: =, +,-=, * =, / =,% =
This is nothing but the operation of assigning values, just to note that for data of non-default data types, type conversions are automatically performed when using assignment operators with arithmetic operators, such as:
Byte j = 5 × j + = 6; / / the following sentence is equivalent to the previous sentence j = (byte) (j + 6)
III. Comparison operator
Comparison operators: = =,! =, >, =, > >: move to the right unsigned, regardless of whether the highest bit on the left is 0 or 1, the left complement 0
System.out.println (2 > 1); / / 1 System.out.println (- 2 > > 1); / /-1 System.out.println (- 2 > 1) / / 2147483647 / *-2 * original code: 1000 0000 0000 0000 00000010 * inverse: 1111 1111 1111 1101 * complement: 1111 1111 1111 1110 * right shift 1 bit operation (operation complement) * * complement: 1111 1111 1111 1110 * original code: 1000000000 0000000 0000000 0000000 * unsigned operation 1 bit (operation complement) (as a complement) * * complement: 0111 1111 1111 1111 * inverse: 0111 1111 1111 1111 * original code: 0111 1111 1111 1111 read here This article "how to use the five operators of Java" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about the article, 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.