In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the realization of division and remainder in Java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the realization of division and remainder in Java".
The two concepts of modular operation and remainder operation overlap but are not completely consistent. The main difference is that the operation is different when dividing negative integers.
For the shaping number aforme b, the methods of modular operation or remainder operation are:
1. Find the integer quotient c = a / b
2. Calculation module or remainder r = a-c * b.
The modular operation and the remainder operation are different in the first step:
When the c value is taken, the remainder operation is rounded to 0 direction, while the modular operation is rounded to negative infinity when taking c value.
The meaning of the operator% varies from environment to environment. Cmax is complementary to Java, and python is a module.
The rules of Java remainder operation are as follows:
A% b = a-(a bank b) * b
Let's look at a piece of code first:
Public class Division_remainder {public static void main (String [] args) {int a = 13 / 5; int b = 13% 5; int c = 5 / 13; int d = 5% 13; int e = 13 /-5; int f =-13 / 5; int h =-13% 5; int j = 13%-5; System.out.println (a + "," + b); System.out.println (c + "," + d); System.out.println (e + "," + f) System.out.println (h + "," + j);}
The result is:
2, 3, 3, 5, 5, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 and 3
Let's make another analysis:
A = 13 / 5, a = 2, which is actually 13 / 5 in mathematics, and the result is 2.
B = 13% 5 and b = 3, which is also a mathematical operation, and the remainder is 3.
C = 5 / 13 c = 0, because the divisor is less than the divisor, the result can be regarded as 0.x, but the int type is an integer type, so the result is only 0.
D = 5% 13 and d = 5, mathematically stipulates that if the divisor is smaller than the divisor, the quotient is 0, the remainder is the divisor itself.
Needless to say, e and f both turn out to be-2.
But how can h and j be a-3, because the symbol of the remainder operation is determined by the first Operand,-13% 5 results in-3, and 13%-5 results in 3.
Thank you for reading, the above is the content of "what is the realization method of division and remainder in Java". After the study of this article, I believe you have a deeper understanding of what is the realization method of division and remainder in Java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.