首页 > 编程语言 >Java课后动手动脑二

Java课后动手动脑二

时间:2023-09-20 17:22:26浏览次数:35  
标签:square Java int 动脑 System 课后 println MESSAGE out

随机数

一、JOptionPane:主要用到四种消息提示框方法:

showConfirmDialog():确认对话框

showInputDialog():输入对话框

showMessageDialog():消息对话框

showOptionDialog():选择对话框

 

主要有五种消息类型,类型不同,图标不同:

• ERROR_MESSAGE

• INFORMATION_MESSAGE

• WARNING_MESSAGE

• QUESTION_MESSAGE

• PLAIN_MESSAGE

 

二、Math.random() * 11, 生成0-10之间的随机数,乘几就是0到几。

 

动手动脑Ⅰ

根本的原理是哈希求值,我们用平衡树验证了一下,当仅仅生成1000个数时,不会重复。

public static void main( String args[] )
{
    double m=Math.pow(2.0,31.0)-1;
    int a=16807;
    int c=0;
    int x;
    Random r=new Random();
    x=r.nextInt();
    int[] b=new int[2000];
    b[0]=x;
    for(int i=1;i<=1000;i++){
        b[i]=(a*b[i-1]+c)%(int)m;
    }
    HashSet<Integer>s=new HashSet<>();
    for(int i=0;i<1001;i++){
        System.out.println(b[i]);
        s.add(b[i]);
    }
    System.out.println(s.size());
}

 

动手动脑Ⅱ

特点:写了两个同名的函数,但是返回值类型和传入的参数不一样。

区分同名函数的方法是,写用不同的形参,返回值类型不会区分函数的不同。

public class Main {
    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()有许多重名函数,但是形参都不同,这是调用函数时区分同名函数的标志。

 

标签:square,Java,int,动脑,System,课后,println,MESSAGE,out
From: https://www.cnblogs.com/litianyu1969/p/17717848.html

相关文章

  • JavaScript数组filter方法
    1.数组filter方法作用筛选数组,将满足条件的元素放入新数组中2.语法:array.filter(function(item,index,arr){})第一个参数:item,必须,当前元素的值第二个参数:index,可选,当前元素在数组中的索引值第三个参数:arr,当前元素所处的数组对象3.filter方法特点(1)函......
  • JAVA——两个List集合求交集、并集和差集(去重)
    https://juejin.cn/post/6899000526613151752@TestpublicvoidsplitGetPositionOne2()throwsException{List<String>stringList=newArrayList<>();stringList.add("a");stringList.add("b");stringList.add(&......
  • javascript处理数组
     letdata=[{"subject_id":948,"xmdw":"长春市实验中学","sbnd":2023,"xmmc":"长春市实验中学食堂厨具设备更换项目"},{"subject_id":949,"x......
  • java相关配置讲解
    1spring:2application:3name:app-service-qms#指定服务名称4profiles:5active:sit#指定本次启动服务运行环境67server:8port:200019ws:10endpoint:9999/MsgTrackSrvPortType/R13402003193?wsdl1112cron:......
  • 无涯教程-JavaScript - BETA.DIST函数
    描述BETA.DIST函数返回beta分布。Beta分布通常用于研究样品中某物百分比的变化。语法BETA.DIST(x,alpha,beta,cumulative,[A],[B])争论Argument描述Required/OptionalXThevaluebetweenAandBatwhichtoevaluatethefunction.RequiredAlphaAparameterof......
  • Java学习之路--GUI编程01
    packagecom.gui.lesson01;importjava.awt.*;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;//GUI编程课堂练习exercise--练习2023.3.14publicclassExerciseDemo{publicstaticvoidmain(String[]args){//总的Frame窗口F......
  • Java学习之路--网络编程相关01
    packagecom.kuang.lesson01;importjava.net.InetAddress;importjava.net.UnknownHostException;//2023.2.28/3.1Java狂神说-网络编程实战-IP地址publicclassTestnetAddress{publicstaticvoidmain(String[]args){//测试iptry{//查询......
  • Java学习之路--网络编程相关02
    packagecom.kuang.lesson02;importjava.io.IOException;importjava.io.OutputStream;importjava.net.InetAddress;importjava.net.Socket;importjava.net.UnknownHostException;//客户端2023.3.4TCP建立客户端和服务端实现信息发送功能publicclassTcpClientDemo01{......
  • Java学习之路--网络编程相关03
    packagecom.kuang.lesson03;importjava.net.DatagramPacket;importjava.net.DatagramSocket;importjava.net.InetAddress;//2023.3.6UDP通信方式实现发送消息----不需要连接服务器publicclassUdpClientDemo01{publicstaticvoidmain(String[]args)throwsExcepti......
  • Java学习之路--网络编程相关04
    packagecom.kuang.lesson04;importjava.net.MalformedURLException;importjava.net.URL;//2023.3.8/9URL下载网络资源publicclassURLDemo01{publicstaticvoidmain(String[]args)throwsMalformedURLException{URLurl=newURL("https://localhost:......