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