Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What operators are included in Java

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you what operators are included in Java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The operators included in Java are arithmetic operators, logical operators, relational operators, and so on.

The arithmetic operator is our usual operations such as addition, subtraction, multiplication and division: in Java, the value on the right is assigned to the left, so the general format is: result = value.

Add (+): result = value1 + value2; for example result = 10 + 10; the result value is 20

Minus (-): result = value1-value2; for example result = 20-10; the resulting value is 10

Multiply (*): result = value1 * value2; for example result = 20 * 10; the result value is 200

Except (/): result = value1 / value2; for example result = 20 / 10; the result value is 2; if the value of value2 is 0, Java throws an exception

Result = value1% value2;, for example, result = 12% 5

Self-increment (+ +): value++ or + + value; means to add 1 to the value of value; there are two ways to write it, one is + + in the front, the other is + + in the back, there is no difference when the two are used alone, but there is a difference when they are used with other variables or other grammars. + + indicates that value is added first and then is calculated; + + explains that value is used first to add 1 to value; for example, value = 10X value = value++ The result of result is 11, because + + is later, so value is used to assign a value to result, and then value is adding 1; for example, the result of result = + + value; result is 11; because + + is in front, the value of value first adds one to 11, and then the value is assigned to result, so the result of result is 11

Self-subtraction (- -): the same logic as self-increment, except that you subtract yourself by 1.

Logical operator: & & (and) | | (or)! (no), the variable judged by the logical operator is boolean, and only true and false

And (& &): result = value1 & & value2; when both value1 and value2 are true, the result of result is true; when any of them is false, the result of result is false; and when the value of value1 is false, value2 does not judge, the whole result result is false; (value! = null & & value.length () > 10); if value = null, the whole result is false and value.length () does not judge In this way, if value = = null;, the exception will not occur later because the operation will not be carried out.

Or (| |): result = value1 | | value2; when both value1 and value2 are false, the result result is false; if one is true, then the result result is true; and if value1 is true, value2 does not need to judge, result is true

Non-(!): result =! the result of value; result is opposite to that of value. If value is true, result is false, then result is true.

Relational operator: (> (greater than), > = (greater than or equal to), =): determine whether the first value is greater than or equal to the second value

Less than (

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report