java% modulus (No. 14th)

Source: Internet
Author: User
Tags modulus

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.