zoukankan      html  css  js  c++  java
  • 2020.10.1收获

    四则运算

    (4)定制是否有乘除法

    package day02;
    
    import java.util.Random;
    import java.util.Scanner;
    
    public class Test {
    
    	public static void main(String args[]) {
    
    		Random rand = new Random();
    		boolean[] bool = new boolean[101];
    		String[] fuhao = new String[] { "+", "-", "*", "/" };
    
    		int n = 0;
    		int length = 0;
    		@SuppressWarnings("resource")
    		Scanner scan = new Scanner(System.in);
    
    		System.out.print("您想练习题目的个数为:");
    		length = scan.nextInt();
    
    		System.out.print("操作数的个数为:");
    		n = scan.nextInt();
    
    		System.out.println("题目中是否出现乘除号:1/0");
    		int chengchu = scan.nextInt();
    	
    		if (chengchu == 1) {
    
    			int[] Number = new int[n];
    			String[] Fh = new String[n];
    
    			for (int i = 0; i < length; i++) {
    				System.out.print(i + 1 + "、");
    				for (int j = 0; j < n; j++) {
    
    					do {
    						Number[j] = 1+rand.nextInt(100);
    						Fh[j] = String.valueOf(fuhao[rand.nextInt(4)]);
    
    					} while (bool[Number[j]]);
    
    					bool[Number[j]] = true;
    
    					if (j != n - 1) {
    						System.out.print(Number[j] + Fh[j]);
    					} else {
    						System.out.print(Number[j]);
    					}
    				}
    				System.out.println();
    
    			}
    
    		}
    
    		if (chengchu == 0) {
    
    			int[] Number = new int[n];
    			String[] Fh = new String[n];
    
    			for (int i = 0; i < length; i++) {
    				System.out.print(i + 1 + "、");
    				for (int j = 0; j < n; j++) {
    
    					do {
    						Number[j] = rand.nextInt(101);
    						Fh[j] = String.valueOf(fuhao[rand.nextInt(2)]);
    
    					} while (bool[Number[j]]);
    
    					bool[Number[j]] = true;
    
    					if (j != n - 1) {
    						System.out.print(Number[j] + Fh[j]);
    					} else {
    						System.out.print(Number[j]);
    					}
    				}
    				System.out.println();
    
    			}
    
    		}
    	}
    }
    

     

    (5) 定制是否有括号(随机插入)

     不会

    (6) 定制数值范围

    System.out.print("数字的最小值为:");
    		int min=scan.nextInt();
    		
    System.out.print("数字的最大值为:");
    		int max=scan.nextInt();
    		
    .........
    
    
    Number[j] = rand.nextInt(max+1-min)+min;
    

      

  • 相关阅读:
    Docker用途 & 和tomcat的区别
    Ubuntu安装Redis
    Ubuntu查看和设置Root账户
    Oracle常用语句
    Redis知识总结
    Blazor学习笔记01: 使用BootstrapBlazor组件 创建一个具有单表维护功能的表格页面
    NET Core之积沙成塔01: 解决Visual Studio 2019 代码提示为英文
    MySQL系统自带的数据库information schema
    Windows安装mysql方法
    数据库之概念
  • 原文地址:https://www.cnblogs.com/ltw222/p/13759650.html
Copyright © 2011-2022 走看看