In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the arithmetic operators of java and how to use them". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "what are the arithmetic operators of java and how to use them?"
Arithmetic operator
Arithmetic operators are used in mathematical expressions, and they play the same role as in mathematics. The following table lists all the arithmetic operators.
The example in the table assumes that the value of integer variable An is 10 and that of variable B is 20:
Operator description + addition-values on both sides of the addition operator-subtraction-left Operand minus right Operand * value / Division-left Operand divided by right Operand% remainder-left Operand divided by the remainder of the right Operand + + self-increment: the value of the Operand increases by 1-- self-subtraction: the value of the Operand decreases 1 example public static void main (String [] args) {int a = 10 Int b = 20; int c = 25; int d = 25; System.out.println ("a + b =" + (a + b)); System.out.println ("a-b =" + (a-b)); System.out.println ("a * b =" + (a * b)); System.out.println ("b / a =" + (b / a) System.out.println ("b% a =" + (b% a)); System.out.println ("c% a =" + (c% a)); System.out.println ("aqu + =" + (aqu +)); System.out.println ("aMub-=" + (Amura -)); / / View the different System.out.println of dumped + and + + d ("dashed + =" + (dumped +)) System.out.println ("+ d =" + (+ d)) } run result "C:\ Program Files\ Java\ jdk1.8.0_192\ bin\ java.exe"-javaagent:C:\ Program Files\ JetBrains\ IntelliJ IDEA 2020.1.3\ lib\ idea_rt.jar=51196:C:\ Program Files\ JetBrains\ IntelliJ IDEA 2020.1.3\ bin "- Dfile.encoding=UTF-8-classpath" C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ charsets.jar C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ deploy.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ access-bridge-64.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ cldrdata.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ dnsns.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ jaccess.jar C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ jfxrt.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ localedata.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ nashorn.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ sunec.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ sunjce_provider.jar C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ sunmscapi.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ sunpkcs11.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ ext\ zipfs.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ javaws.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ jce.jar C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ jfr.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ jfxswt.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ jsse.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ management-agent.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ plugin.jar C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ resources.jar;C:\ Program Files\ Java\ jdk1.8.0_192\ jre\ lib\ rt.jar D:\ JavaProject\ 20210402\ out\ production\ 20210402 "Testa + b = 30a-b =-10a * b = 200b / a = 2b% a = 0c% a = 5a * + = 10a Testa-= 11dink + = 25roomd = 27Process finished with exit code 0 relational operator description = = check if the values of the two operands are equal, if the conditions are true.! = check whether the values of the two operands are equal, and the condition is true if the values are not equal. > check whether the value of the left Operand is greater than that of the right Operand. If so, the condition is true. = check whether the value of the left Operand is greater than or equal to the value of the right Operand, and if so, the condition is true. B)); System.out.println ("a
< b = " + (a < b) ); System.out.println("b >= a = "+ (b > = a)); System.out.println (" b > = 2 = "+ c); c > > = 2; System.out.println (" c > = 2 = "+ c); c & = a; System.out.println (" c & = a = "+ c); c ^ = a; System.out.println (" c ^ = a = "+ c); c | = a" The System.out.println ("c | = a =" + c);} runs as follows: C = a + b = 30c + = a = 40c-= a = 30c * = a = 300c / = a = 1c% = a = 5c = 2 = 5c > > = 2 = 1c & = a = 0c ^ = a = 10c | = a = 10Process finished with exit code 0Java operator priority category operation relevance suffix () []. (dot operator) unary expr++ expr- from left to right + + expr--expr+-~! From right to left multiplicative * /% left to right additive +-left to right shift > =
< >=
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.