ICode9

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

四则运算课上总结

2022-09-12 11:02:18  阅读:174  来源: 互联网

标签:总结 反码 int 四则运算 补码 System nextInt 课上 out


import java.lang.Math; import java.util.Scanner; public class Zzz { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("输入要打印的数量:"); int n=s.nextInt(); System.out.println("输入每行的个数:"); int m=s.nextInt(); System.out.println("是否有乘除法(输入0或1):"); int o=s.nextInt(); int p=4; if(o==0) { p=2; } int a=0; System.out.println("输入最大范围:"); int r=s.nextInt(); int f=s.nextInt(); System.out.println("是否有含括号(输入0或1):"); int t=s.nextInt(); for(int i = 0;i <n ;i++) { int firNum = (int)(f + Math.random()*r-f); int secNum = f + (int)(Math.random()*r-f); int operaNum = 1 + (int)(Math.random()*p); if(operaNum == 1) { System.out.print(firNum + "+" + secNum + "="+" "); } if(operaNum == 2) { System.out.print(firNum + "-" + secNum + "="+" "); } if(t==0&&operaNum == 3&&o==1) { System.out.print(firNum + "*" + secNum + "="+" "); } if(t==0&&operaNum == 4&&o==1) { if(secNum != 0) { System.out.print(firNum + "/" + secNum + "="+" "); } else if(firNum != 0) { System.out.print(secNum + "/" + firNum + "="+" "); } else { System.out.print(30 + "/" + 15 + "="+" "); } } int e=1 + (int)(Math.random()*2); if(t==1&&operaNum == 3&&o==1) { int b=(int)(f+Math.random()*r-f); int c = f + (int)(Math.random()*r-f); int d = 1 + (int)(Math.random()*2); if(d == 1) { if(e==1) { System.out.print(firNum+"*" + "("+b + "+" + c +")"+ "="+" "); } else { System.out.print("("+b + "+" + c +")"+"*" + secNum+ "="+" "); } } if(d == 2) { if(e==1) { System.out.print(firNum+"*" + "("+b + "-" + c +")"+ "="+" "); } else { System.out.print("("+b + "-" + c +")"+"*" + secNum+ "="+" "); } } } if(t==1&&operaNum == 4&&o==1) { int b=(int)(f+Math.random()*r-f); int c = f + (int)(Math.random()*r-f); int d = 1 + (int)(Math.random()*2); if(d == 1) { if(e==1) { System.out.print(firNum+"/" + "("+b + "+" + c +")"+ "="+" "); } else { System.out.print("("+b + "+" + c +")"+"/" + secNum+ "="+" "); } } if(d == 2) { if(e==1) { System.out.print(firNum+"/" + "("+b + "-" + c +")"+ "="+" "); } else { System.out.print("("+b + "-" + c +")"+"/" + secNum+ "="+" "); } } /*if(secNum != 0) { if(e==1) { System.out.print("/" + secNum + "="+" "); } else { System.out.print("/" + secNum + "="+" "); } }*/ /*else if(firNum != 0) { System.out.print("/" + firNum + "="+" "); }*/ else { System.out.print(30 + "/" + 15 + "="+" "); } } a=a+1; if(a==m) { System.out.println("\n"); a=0; } } } }

 

正数的原码、补码、反码都一样;

负数的原码、反码转换:符号位不变,数值位按位取反;

负数的原码、补码转换:符号位不变,数值位按位取反,末位+1,【快速求法为:符号位不变,从右往左找第一个1,这个1左边的取反,右边的不变】;

负数的反码、补码转换:反码转补码,末位+1;补码转反码,末位-1。

 

 

课上遇到了就是怎么加阔号的一个问题根据,然后在网上搜到了一些方法然后进行改写

标签:总结,反码,int,四则运算,补码,System,nextInt,课上,out
来源: https://www.cnblogs.com/ruipengli/p/16685675.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

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

ICode9版权所有