Division operations and modulo

Source: Internet
Author: User

Package review20140420;
/*
* Division and modulo (integer divided by integer, there will be a divisor can not be zero exception)
*/
public class Test2 {
Entrance to the program
public static void Main (string[] args) {
/* Define variable a,b*/
Double a=5.2;
Double b=3.1;
Division operation
Double div=a/b;
Modulo operation
Double mod=a%b;
/* Print Results */
System.out.println (DIV);
SYSTEM.OUT.PRINTLN (MoD);
/*5.0 divided by 0 and 5 divided by 0.0, the output is infinity large */
System.out.println (5.0/0);
System.out.println (5/0.0);
/*0 divided by 0.0 and 0.0 divided by 0, output non-number: nan*/
System.out.println (0/0.0);
System.out.println (0.0/0);
/*-5.0 divided by 0 and-5 divided by 0.0, output negative infinity */
System.out.println ( -5/0.0);
System.out.println ( -5.0/0);
/* Divisor is not 0 exception */
System.out.println (5/0);
System.out.println ( -5/0);
}
}

Output results

1.6774193548387097
2.1
Infinity
Infinity
NaN
NaN
-infinity
-infinity
Exception in thread "main" java.lang.ArithmeticException:/By zero
At review20140420. Test2.main (test2.java:28)

Division operations and modulo

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.