ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

算术运算符除号:/

2020-02-02 13:39:46  阅读:79  来源: 互联网

标签:num1 num2 算术 double System 运算符 println 除号 out


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

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有