1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anni [7]
3 years ago
9

Write code to simulate rolling a six-sided die. A six-sided die has the values 1-6 on its faces. The program first asks user for

the number of rolls and then rolls the die for the specified times. The program displays the face values, the number of occurrences of each value, and the frequency of each value in a neat tabular format. Use an int array to store the number of occurrences of 6 values and a double array to store the frequency of 6 values. Display 5 decimal places for floating-point values.
Computers and Technology
1 answer:
torisob [31]3 years ago
4 0

Answer:

import java.util.Random;

import java.util.Scanner;

public class Dice {

 

  public static void main(String[] args) {

     

      Scanner sc = new Scanner(System.in);

      System.out.print("how many times want to roll: ");

      int n = sc.nextInt();

     

      Random ran = new Random();

      int[] arr = new int[7];

      int i = 0;

      while(i < n) {

          int r = ran.nextInt(6)+1; //1-6

          arr[r]++;

          i++;

      }

     

      double[] frequency = new double[7];

      for(i=1; i<7; i++) {

          frequency[i] = arr[i]/(double)n;

      }

     

      System.out.println("Number\t\toccurrences\t\tfrequency");

      for(i=1; i<7; i++) {

          System.out.print(i+"\t\t"+arr[i]+"\t\t\t");

          System.out.println(String.format("%.5f", frequency[i]));

      }

  }

}

/*

Sample run:

how many times want to roll: 400

Number       occurrences       frequency

1       69           0.17250

2       71           0.17750

3       72           0.18000

4       59           0.14750

5       62           0.15500

6       67           0.16750

*/

Explanation:

You might be interested in
What is the purpose of memory address?​
IceJOKER [234]

Answer:

A memory address is a unique identifier used by a device or CPU for data tracking.

5 0
2 years ago
Read 2 more answers
Which of the following is the correct order of laws (from local to state to federal)
professor190 [17]

Answer:

That, Federal law > Constitutional Law > State law > Local ordinances

Explanation:

4 0
3 years ago
ShellShock had the potential for an unauthorized user to gain access to a server. It affected many internet-facing services, whi
mina [271]

Answer: Windows

Explanation:

ShellShock: Also called Bashdoor, it is a security bug which is found in the Bash shell of operating system e.g. Unix. It allows the hacker to execute scripts and commands by gaining unauthorized access. This affects many machines, devices that use Bash. Servers like web servers are most affected as most of them run Unix based OS like OS X. Most vulnerable are those who use Unix or Linux operating systems.  

Microsoft Windows does not use Bash so it does not directly affect Windows os. For those who are using Windows PC, Windows phones and websites that are developed by MS software are non-vulnerable to ShellShock.

4 0
3 years ago
This is really not a question but yall should texts me I need friends:))
noname [10]

Answer:

if ur lonely i suggest an app/website called mylol

Explanation:

fdsjafklsuhfkjfudhjkfewuhfdjk fdjs afujijf kldsaflkdjslajrfewiofjdjsahfruifhgijdsk fdsj fds

8 0
3 years ago
Read 2 more answers
Nog
STatiana [176]

Answer: False

Explanation:

The statement that "Peacekeeper text is non-printing text that indicates where you can type" is false.

The non-printing text which shows where on exam type is referred to as the peaceholder text. It is usually an hint which can be used to fill in the actual text.

8 0
3 years ago
Other questions:
  • DNA is the fundamental encoding of the instructions that govern the operation of living cells and, by extension, biological orga
    5·1 answer
  • ​Microsoft claims that the microsoft project software can _____.
    11·1 answer
  • What area on the Microsoft® Publisher® application screen shows the name of the publication?
    9·1 answer
  • How do I learn coding? Python
    5·2 answers
  • What is the output of the code snippet given below?string s = "abcde";int i = 1;while (i &lt; 5){ cout &lt;&lt; s.substr (i, 1);
    11·1 answer
  • C:/Users/Documents/resume.docx Where is the "resume" document located in this file structure?
    12·1 answer
  • What is Error Code: 232011
    11·2 answers
  • - O conhecimento na Educação Física, normalmente passa do senso comum e vai para um conhecimento mais formal, ou seja, do conhec
    7·1 answer
  • Find each of the following products using distributive property a) 735 × 16​
    12·1 answer
  • What is an example of a recent development in technology
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!