算术运算符除号:/
作者:互联网
java除号:/ 的使用
public class Fighting{
public static void main(String[] args){
int num1 = 7;
int num2 = 5;
int result = num1/num2;
double result2 = num1/(double)num2;//结果保留double
double result3 = num1/(num2+0.0);//(num2+0.0)结果保留double型
double result4 = num1/num2+0.0;//num1/num2结果为int +0.0 )结果为double
System.out.println("num1/num2 = "+result);
System.out.println("num1/(double)num2 = "+result2);
System.out.println("num1/(num2+0.0) = "+result3);
System.out.println("num1/num2+0.0 = "+result4);
System.out.println("-7/5 = "+(-7/5));
System.out.println("7/-5 = "+(7/-5));
System.out.println("-7/-5 = "+(-7/-5));
}
}
bear xiao
发布了9 篇原创文章 · 获赞 0 · 访问量 240
私信
关注
标签:num1,num2,算术,double,System,运算符,println,除号,out 来源: https://blog.csdn.net/weixin_44750594/article/details/104142409