其他分享
首页 > 其他分享> > 四则运算课上总结

四则运算课上总结

作者:互联网

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