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;
    

      

  • 相关阅读:
    oracle 按关键字排序前几行
    oracle 查看某表的前10行
    linux 7安装部署Redis
    oracle 查看库表状态
    centos 7 启动和关闭zabbix 服务
    oracle 创建用户密码及赋予登录权限
    linux 控制root登录宿主机时间
    centos 更改用户登录宿主机时间
    oracle 查询、创建、删除 数据库用户
    Django基础四之模板系统
  • 原文地址:https://www.cnblogs.com/ltw222/p/13759650.html
Copyright © 2011-2022 走看看