为小学生出四则运算题目.java

匿名 (未验证) 提交于 2019-12-02 21:52:03
import java.util.Scanner; import java.util.Random; public class test{ 	public static int  s1 = new Random().nextInt(100); 	public static int  s2 = new Random().nextInt(100); 	public static int  s3 = new Random().nextInt(100); 	public static void main(String[] args) { 		Scanner in = new Scanner(System.in); 		System.out.println("请输入想要的算法个数:"); 		int amout = in.nextInt(); 		System.out.println("请输入想要每行个数:"); 		int line = in.nextInt(); 		int[][] sum = new int[10000][3]; 		for(int i=0;i<amout;i++) { 			if(i%line==0) { 				System.out.print("\n"); 			} 			s3 = new Random().nextInt(100); 			     sum[i][2]=s3;          		s1 = new Random().nextInt(100);   	            s2 = new Random().nextInt(100); 			if((s3%4)==0){ 	            if(s2>s1){ 	            	while(s2>s1) { 	            		s1 = new Random().nextInt(100);           	            s2 = new Random().nextInt(100); 	            	} 	    			} 			} 			if((s3%4)==1) {                 sum[i][0]=s1;                 sum[i][1]=s2; 			} 			 if((s3%4)==2) { 	            if(s1*s2>100) { 	            	while(s1*s2>100){ 	    				s1 = new Random().nextInt(100); 	    	            s2 = new Random().nextInt(100); 	    	        } 	            } 			} 			 if((s3%4)==3) { 				  while(s2==0) {   	                s2 = new Random().nextInt(100);   	            } 			      if(s1%s2!=0) { 			    	  while(s2==0) { 	    	                s2 = new Random().nextInt(100); 	    	            } 			    	  while(s1%s2!=0){ 		    				s1 = new Random().nextInt(100); 		    	            s2 = new Random().nextInt(100); 		    	            while(s2==0) { 		    	                s2 = new Random().nextInt(100); 		    	            } 		            	} 		            } 			  }                  sum[i][0]=s1;                  sum[i][1]=s2;                  if(i>1) {     		     if(sum[i-1][0]==sum[i][0]&&sum[i-1][1]==sum[i][1]&&sum[i-1][2]%4==sum[i][2]%4) {     			    	 do {     			    		 sum[i][0]=new Random().nextInt(100);     			    		 sum[i][1]=new Random().nextInt(100);     			    		 sum[i][2]=new Random().nextInt(100);     			    	 }while(sum[i][0]!=sum[i-1][0]&&sum[i][1]!=sum[i-1][1]&&sum[i][2]%4!=sum[i+1][2]%4);     			     }     		     }     		     if(s3%4==0) {     		    	 System.out.print(i+1 +":"+ s1 + "-" + s2 +"=  ");     		     }     		     if(s3%4==1) {     		    	 System.out.print(i+1 +":"+ s1 + "+" + s2 +"=  ");     		     }     		     if(s3%4==2) {     		    	 System.out.print(i+1 +":"+ s1 + "*" + s2 +"=  ");     		     }     		     if(s3%4==3) {     		    	 System.out.print(i+1 +":"+ s1 + "/" + s2 +"=  ");     		     } 		   }         } 	 }	

  程序设计思路:程序主要运用了Random函数产生随机数,将s3%4做为符号确定数,再在其中每一个条件中控制该运算符的相应条件。最后在用数组存入相应数据,将其进行判断。最后按照要求输出!

       设计程序可以锻炼逻辑思维能力,以后会每天坚持敲写代码,提高自己的编程能力。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!