.
I want to record the number of times (1 to 6) of rolling dice n times using Java and display the graph with (*).
(Example)
1: ********
2: **
3: ***********
~~~~~~~~~~~~~~~~
I've come to the point where I can output a random number using the Rondom class, but I don't know the future. please tell me.
import java.util.Scanner;
import java.util.Random;
public class test_1 {
public static void main (String [] args) {
Scanner scan = new Scanner (System.in);
Random rand = new Random ();
System.out.print ("Number of dice rolls>");
int max = scan.nextInt ();
for (int i = 0;i
}
System.out.println ();
}
}
-
Answer # 1
-
Answer # 2
I don't know if it works because I haven't tested it, but what about it?
import java.util.Scanner; import java.util.Random; public class test_1 { public static void main (String [] args) { Scanner scan = new Scanner (System.in); Random rand = new Random (); System.out.print ("Number of dice rolls>"); int max = scan.nextInt (); int diceLog [] = new int [6]; for (int i = 0;i
By the way,
int dice = rand.nextInt (6) + 1; System.out.println (dice); diceLog [dice-1] = diceLog [dice-1] + 1;
There is no need to output this part, but if you don't check what the value is, you can't check whether the last graph is correct or not.
Related articles
- java - creating a seat reservation system using an array
- java main method not found using eclipse
- age verification program using java
- exercises using java scanner
- java - launch spring app using postgresql from outside
- displaying minimums using java methods and arrays
- assign random numbers to java array
- java - i want to extract all the data using cursor
- java - file upload using spring security
- creating a booking form page using the wordpress plugin mts simple booking-c
- java - updating variables using charat ();
- java - cannot compile using package (mac)
- [java] i want to prohibit input of only blanks using regular expressions
- java - random range specification
- [java] random number question
- java - cannot pass data (screen transition) using servlet
- java - i want to perform fuzzy search using bind variables
- i want to create a frame using jframe in java, but it crashes
- java - i want to get the date and time continuously by calculation without using sleep or timer
- java - the image when taking a picture using android studio camera 2 is black
I think you can do this by writing it yourself ...
First, let's record. What would you do if you did it manually?