zoukankan      html  css  js  c++  java
  • 动手动脑-随机数和重载

    随机生成自己想要个数的数字

    package shangke.disanzhou;
    
    import java.util.Random;
    import java.util.Scanner;
    
    public class dongshoudongnao {
    
    	public static void main(String[] args) {
    		long   a,b,n;
    		Scanner shuru=new Scanner(System.in);
    		n=shuru.nextInt();
    		Random R = new Random();
    		 a=R.nextInt();
    		 b= Integer.MAX_VALUE;
    		for(int i=0;i<n;i++)
    		{
    			a=(a*16807)%b;
    			System.out.println(a);
    		}
    	}
    }
    

      

    可根据自己需要选择数量打印随机数

    package shangke.disanzhou;
    
    //MethodOverload.java
    //Using overloaded methods
    
    public class MethodOverload {
    
        public static void main(String[] args) {
            System.out.println("The square of integer 7 is " + square(7));
            System.out.println("
    The square of double 7.5 is " + square(7.5));
        }
    
        public static int square(int x) {
            return x * x;
        }
    
        public static double square(double y) {
            return y * y;
        }
    }

    这个函数是对函数重载的一种利用方法,函数参数类型不同,参数个数不同,或者参数类型顺序不同都可以进行函数的重载

  • 相关阅读:
    汉诺塔IX
    N!
    卡片游戏
    vuejs 2—bind
    vuejs 1—基础
    困难的串 Kryptn Factor Uva129
    JavaScript13—JSON
    JavaScript练习—二级菜单
    JavaScript12—tools.js
    JavaScript11—定时器
  • 原文地址:https://www.cnblogs.com/yizhixiaozhu/p/11595580.html
Copyright © 2011-2022 走看看