23.9.22

一、随机数生成器:使用公式生成指定数量的随机数

import java.util.Scanner;

public class random {
public static void main(String[] args) {
int n;
int a = 2147483647;
int c = 0;
int m = 16807;
Scanner ci = new Scanner(System.in);
n = ci.nextInt();
int x = n;
for(int i = 0; i < n; i++){
System.out.println(x);
x = (a*x+c)%m;
c++;
}
}
}

二、方法的重载:要求参数表不同

public class MethodOverload {

public static void main(String[] args) {
System.out.println("The square of integer 7 is " + square(7));
System.out.println("\nThe 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;
}
}

 

posted @   a_true  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示