MoD and% differences in Java

Source: Internet
Author: User

Busy today, see the article HashMap working principle of the blog, in the above to see the mod (Take the mold), the thought of taking the remainder symbol%.

Then we looked at some of the information, and now summarize:


Modulo and redundancy methods in Java:

1, Take the mold demo

        package com.lbb.test;             import java.math.BigInteger;         public class RomTest {        public  Static void main (String[] args)  {             BigInteger b1;             biginteger b2;            biginteger b3;             b1 = new biginteger ("- ");            b2 = new  BigInteger ("4");             b3 = b1.mod ( B2);                          system.out.println ("B3:"  + b3);                         integer i1  = -20;Integer i2 = -3;Integer i3 = i1 % i2; System.out.println ("i3:"  + i3);        }         }

Note: The values calculated by the modulo mod () method are non-negative, especially if the parameters inside the modulo B2 must be positive.


For the remainder of the symbol, there is no special requirement for the divisor and divisor, only the divisor cannot be zero, otherwise it will appear java.lang.ArithmeticException (except 0 exception)

Note: The value is calculated by the percent, positive, negative, 0 can be.


This article is from the "focus on Development Technology" blog, please be sure to keep this source http://bingge2015.blog.51cto.com/4332222/1900016

MoD and% differences in Java

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.