• 随机数应用


    10.10

    随机数模拟骰子滚动:

    代码部分:

    package lianxi;
    import java.util.*;
    import javax.swing.*;
    public class bo {
    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 );
    }


    }

    运行结果:

  • 相关阅读:
    pytest常用命令行
    pytest中一些常用插件
    case运行失败进行重试-pytest-rerunfailures插件
    adb 在自动化测试中的截图
    app的冷启动和热启动
    ATX
    UI自动化中常用的三种等待
    allure
    性能指标分析
    接口自动化之接口依赖解决
  • 原文地址:https://www.cnblogs.com/092e/p/14142545.html
Copyright © 2020-2023  润新知