加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

2019-9-23

发布时间:2020-12-15 07:35:24 所属栏目:Java 来源:网络整理
导读:一、动手动脑1 1.生成随机数: ? ? ?2.代码: package s0923; import java.util.Scanner; import java.util.Random; public class sy3 { static Scanner sc=new Scanner(System.in); public static void main(String[] args) { System.out.print("请输入想要

一、动手动脑1

1.生成随机数:

?

?

?2.代码:

package s0923;

import java.util.Scanner;
import java.util.Random;
public class sy3 {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
System.out.print("请输入想要生成的随机数的个数:");//提示用户输入想要生成的随机数个数
int n=0;
n=sc.nextInt();
System.out.println("生成的随机数为:");
Random random=new Random();
int s=random.nextInt(100);
for(int i=1;i<=n;i++){
s=(7^5*s+0) % 2147483647;
System.out.print(s+" ");//输出生成的随机数
if(i%5==0){//每行5个随机数
System.out.print("n");}}}}

3.运行测试

?

? ? ? ? ?动手动脑2

1.题目:请看以下代码,你发现了有什么特殊之处吗?

? ? ? ? ? ? ??函数重载:函数名相同,参数类型不同

// 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("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;}}

?

二、课后实验

查看一下JDK中System.out.println()方法,你发现了什么?

JDK中有许多与System.out.println()同名的重载方法。为了使编程时输出更加方便,所以把输出的方法都同名重载。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读