zoukankan      html  css  js  c++  java
  • JAVA语法基础作业——动手动脑以及课后实验性问题 (二)

    一、随机数

    import java.util.Random;


    public class Suijishu {

       private static final int N = 200;

       private static final int LEFT = 40;

       private static final int RIGHT = 10000;

       private static long x0 = 1L;

       private long a = 1103515245L;

       private long c = 12345L;

       private long m = 2147483648L;

                           // 产生随机数

       private long rnd ( long r ){

           r = ( r * a + c ) % m; //Xn+1=(aXn + c)mod m
           return r;
       }

       private long little1 ( int a, int b, long rand ){

           return a+rand%(b-a+1);

       }

       private void recursion ( int count, long rand ){

             if (count >= N){return;}

       rand = rand (rand);

       long r = little1 (LEFT, RIGHT, rand);

       System.out.print (r + " ");

       recursion (++count, rand);

       }

       private long little(int left2, int right2, long rand) {
          // TODO Auto-generated method stub
          return 0;
       }

       public static void main ( String[] args ){

          Suijishu recur = new Suijishu ();
          recur.recursion (0, x0);

       }

    }

    二、方法重载

    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;
       }
    }

      满足以下条件的两个或多个方法构成“重载”关系:
        (1)方法名相同;
        (2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。
      注意:方法的返回值不作为方法重载的判断条件。

  • 相关阅读:
    [BZOJ4876][ZJOI2017]线段树
    [FJOI2016]建筑师(斯特林数)
    WC2018伪题解
    [BZOJ3514]CodeChef MARCH14 GERALD07加强版(LCT+主席树)
    [BZOJ2594][WC2006]水管局长加强版(LCT+Kruskal)
    [洛谷3796]【模板】AC自动机(加强版)
    [洛谷3808]【模板】AC自动机(简单版)
    [BZOJ3261]最大异或和
    [BZOJ3439]Kpm的MC密码
    [POI2006]Periods of Words
  • 原文地址:https://www.cnblogs.com/XiaoPiHaiEr/p/5962938.html
Copyright © 2011-2022 走看看