四则运算课上总结
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。
课上遇到了就是怎么加阔号的一个问题根据,然后在网上搜到了一些方法然后进行改写
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署