• java课后作业2


    动手动脑

    编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数

    import java.util.Random;
    import java.util.Scanner;
    public class Make {
          public static void main(String[] args){
                 Random rand=new Random();
                 Scanner scan = new Scanner(System.in);
                 int n;
                 n = scan.nextInt();
                 int x=rand.nextInt(100);
                 for(int i=1;i<=n;i++)
                 {
                  x=(int) ((7^5*x+0)%(Math.pow(2,31)));
                  System.out.print(x+" ");
                  if(i%10==0)
                   System.out.println();
                 }
        }
    }

    结果

    10
    293 1470 7345 36722 183613 918070 4590345 22951722 114758613 573793070

    方法重载

    // 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;
       }
    }
     
     结果
    The square of integer 7 is 49
    The square of double 7.5 is 56.25
  • 相关阅读:
    MySQL5.6升级5.7步骤
    PG数据库学习随笔(1)
    MySQL 8017+版本的clone-plugin 应用
    AWS多元复制到EC2机器
    AWS告警优化
    mongo微服务搭建
    py执行数据库存储过程
    mysql temporary table表一个机智用法:
    记录ddl操作
    sql改写
  • 原文地址:https://www.cnblogs.com/songxinai/p/11583926.html
Copyright © 2020-2023  润新知