In Java programming, the percent sign % is used for remainder operations, and the division sign / is used for division operations. The percent sign returns the remainder (integer), and the division sign returns the quotient (floating point number). The two are used in different situations: % is used when the remainder is required, and / is used when the quotient is required.
The difference between % and / in Java
In the Java programming language, the percent sign (%) and The division sign (/) is two different operators used to perform different mathematical operations.
The percent sign (%)
a % b
, where a
and b
are numbers. a
divided by b
. Example:
7 % 3
The result of the operation is 1 because the remainder of 7 divided by 3 is 1. 12 % 5
The result of the operation is 2 because the remainder of 12 divided by 5 is 2. The division sign (/)
a / b
, where a
and b
are numbers. a
by b
, returned in the form of a floating point number. Example:
7 / 3
The result of the operation is 2.333333 because the quotient of 7 divided by 3 is 2.333333 (3 decimal points). 12 / 5
The result of the operation is 2.4 because the quotient of 12 divided by 5 is 2.4. Key differences
The above is the detailed content of The difference between % and / in java. For more information, please follow other related articles on the PHP Chinese website!