Java modulo operation support type: Character type (excluding negative numbers), byte type, short integer, Shaping, Long Integer, single-precision floating point, double-precision floating-point type
Java Parity judgment
To judge with even numbers
If you judge with odd numbers, the following problems occur:
Public static void main (string[] args) { int arrs[] = { 2, 1, 0,-1,-2}; For (int i = 0; i < arrs.length; i++) {System. Out.println (Arrs[i] + (Arrs[i]% 2 = = 1? " is odd": "is even")); } }
2是偶数1是奇数0是偶数-1是偶数(问题所在,-1是奇数)-2是偶数
This problem can be solved by using even numbers as odd-even judgments. Note: In integers, the number that cannot be divisible by 2 is called odd. In daily life, people usually call odd numbers as singular, which is relative to even numbers.[1] odd numbers can be divided into positive and negative odd numbers. The odd mathematical expressions are:Positive odd number: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33 ... negative odd:-1,-3,-5,-7,-9,-11,-13,-15,-17,-19,-21, -23.-25,- 27,-29,--record My learning process--quote from csdn:insping
java% modulus (No. 14th)