首页 > 其他分享 >动手动脑

动手动脑

时间:2023-09-22 23:00:54浏览次数:28  
标签:lain1 square int double 动脑 动手 static public

 

 

 

 

 

 

 

package lain1;
import javax.swing.*;

public class RollDie {
   public static void main( String args[] )
   {
      int frequency1 = 0, frequency2 = 0,
          frequency3 = 0, frequency4 = 0,
          frequency5 = 0, frequency6 = 0, face;
   
      // summarize results
      for ( int roll = 1; roll <= 6000; roll++ ) {
         face = 1 + (int) ( Math.random() * 6 );
   
         switch ( face ) {
            case 1:
               ++frequency1;
               break;
            case 2:
               ++frequency2;
               break;
            case 3:
               ++frequency3;
               break;
            case 4:
               ++frequency4;
               break;
            case 5:
               ++frequency5;
               break;
            case 6:
               ++frequency6;
               break;
         }
      }

      JTextArea outputArea = new JTextArea( 7, 10 );

      outputArea.setText(
         "Face\tFrequency" +
         "\n1\t" + frequency1 +
         "\n2\t" + frequency2 +
         "\n3\t" + frequency3 +
         "\n4\t" + frequency4 +
         "\n5\t" + frequency5 +
         "\n6\t" + frequency6 );

      JOptionPane.showMessageDialog( null, outputArea,
         "Rolling a Die 6000 Times",
         JOptionPane.INFORMATION_MESSAGE );
      System.exit( 0 );
   }
}

 

 

// MethodOverload.java
// Using overloaded methods
package lain1;
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;
    }
}

 

标签:lain1,square,int,double,动脑,动手,static,public
From: https://www.cnblogs.com/kongxiangzeng/p/17723568.html

相关文章

  • 第三周课后动手动脑
     publicstaticvoidmain(String[]args){System.out.println("Thesquareofinteger7is"+square(7));System.out.println("\nThesquareofdouble7.5is"+square(7.5));}publicstaticintsquare(intx)......
  • 《动手学深度学习 Pytorch版》 7.5 批量规范化
    7.5.1训练深层网络训练神经网络的实际问题:数据预处理的方式会对最终结果产生巨大影响。训练时,多层感知机的中间层变量可能具有更广的变化范围。更深层的网络很复杂容易过拟合。批量规范化对小批量的大小有要求,只有批量大小足够大时批量规范化才是有效的。用\(\bol......
  • 9.18动手动脑笔记整理
    64k的文件是什么概念呢?1行代码大概(平均)是30字节,64k的源代码是2184行如果代码风格好一点,再多一些空行的话,差不多也就是3000行上下Java程序中最基本的构造单元是类,而类中最重要的成员就是方法  类方法的编写:只需创造一个类,然后为其编写声明为public的函数即可 ......
  • 动手动脑
    packagerandom;importjava.util.Random;publicclasstestseed1000{publicstaticvoidmain(String[]args){Randomran=newRandom(System.currentTimeMillis());for(inti=0;i<1000;i++){System.out.println(ran.nextInt());......
  • 动手动脑
    importjava.math.BigInteger;importjava.util.Scanner;publicclassCalculateN{/***@paramargs*/publicstaticvoidmain(String[]args){System.out.print("������N��");Scannerscanner=newScanner(System......
  • 动手动脑
    X(n+1)=(a*X(n)+c)modmModulus=231-1=int.MaxValueMultiplier=75=16807C=0当显示过231-2个数之后,才可能重复。动手动脑:编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数。publicclassRandomnNumberGenerator{privatestaticfinallongMODULUS......
  • Java动手动脑
    数学函数的掌握可以是计算更简单publicclassTestMath{ publicstaticvoidmain(String[]args) { /*---------下面是三角运算---------*/ //将弧度转换角度 System.out.println("Math.toDegrees(1.57):"+Math.toDegrees(1.57)); //将角度转换为弧度 System.out.printl......
  • 9.22动手动脑
    一、动手动脑1importjava.util.Random;publicclassRandomNumberGenerator{publicstaticvoidmain(String[]args){generateRandomNumbers(1000);}publicstaticvoidgenerateRandomNumbers(intcount){intmodulus=231-1;......
  • 9.22动手动脑
    观察以下代码,你发现了有什么特殊之处吗?packagedongshou1;publicclassMehodOverload{publicstaticvoidmain(Stringargs[]){System.out.println("Thesquareofinteger7is"+square(7));System.out.println("Thesquareofinteger7.5is&quo......
  • 9.22动手动脑
    观察以下代码,你发现了有什么特殊之处吗?123456789101112131415161718192021222324252627282930313233343536373839404142434445package dongshou1;    public class MehodOverload{ public static ......