zoukankan      html  css  js  c++  java
  • 数组----第一题

    一:题型:
    * 获取5个随机数,要求随机数含10和99)之间的奇数
    * ,是10-99(包並且存入到数组中。
    * 最后用无返回值有参数的方法遍历该数组。

    package demo;
    
    import java.util.Random;
    
    
    public class demo01 {
        public static void text1(){
            /*
             * 获取5个随机数,要求随机数含10和99)之间的奇数
             * ,是10-99(包並且存入到数组中。
             * 最后用无返回值有参数的方法遍历该数组。
             */
            Random random = new Random();
            int[]arr = new int[5];
            int index = 0;
            //完成后,开始while循环
            while(true){
                int nextInt = random.nextInt(89);//获取89个随机数,但是得让数从十开始,所以+10,也就是从10--99的数
                nextInt+=10;
                //完成后获取奇数
                if(nextInt%2==1){
                    arr[index]=nextInt;
                    ++index;
                }
                if(index==5){
                    break;
                }
            }
            text2(arr);
        }
        public static void text2(int[] arr){
            for (int i = 0; i < arr.length; i++) {
                System.out.println(arr[i]);
            }
        } 
    }
     
  • 相关阅读:
    BigDecimal 和NumberFormat及 获取总页数的应用
    格式化小数点和百分号 DecimalFormatter
    Vue 项目开发
    js 对象补充
    Vue 实例成员
    Vue 指令
    Vue 介绍
    Vue
    request-html
    Python 中的经典类新式类
  • 原文地址:https://www.cnblogs.com/wsx123/p/13741419.html
Copyright © 2011-2022 走看看