标签:
package review20140420;
/*
* 除法和取模(整数除以整数,会出现除数不能为零的异常)
*/
public class Test2 {
//程序的入口
public static void main(String[] args) {
/*定义变量a,b*/
double a=5.2;
double b=3.1;
//除法运算
double div=a/b;
//取模运算
double mod=a%b;
/*打印结果*/
System.out.println(div);
System.out.println(mod);
/*5.0除以0和5除以0.0,输出正无穷大*/
System.out.println(5.0/0);
System.out.println(5/0.0);
/*0除以0.0和0.0除以0,输出非数:NaN*/
System.out.println(0/0.0);
System.out.println(0.0/0);
/*-5.0除以0和-5除以0.0,输出负无穷大*/
System.out.println(-5/0.0);
System.out.println(-5.0/0);
/*除数不为0异常*/
System.out.println(5/0);
System.out.println(-5/0);
}
}
输出结果
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)
标签:
原文地址:http://www.cnblogs.com/ygjcf/p/5414031.html