This is my first time putting a code together for Java based on my own so i was hoping if you someone would be kind enough to review and provide feedback or constructive criticism on this code.
The goal is to roll 2 dice and 10k times. add pairs and display their frequency.
The code runs fine but maybe I am overlooking some logical error or a better way to do this.
/**
* Use the Random Number generator to write a java application that simulates a pair of dice.
* Throwing the pair of dice 10,000 times- Add the values for the pair
* Print the frequency at the end of 10,000 runs
* @author
*
*/
import java.util.Random;
public class diceSimulation {
public static void main(String[] args) {
/**
* Declare variables and store dice max roll in Thousand
*/
final int THOUSAND = 10000;
int counter, dice1, dice2;
//initiate an array with elements to keep count
int [] diceValue = new int [7];
// display welcome message. no other purpose but trial
welcome ();
// create new instance of random
Random rollDice = new Random();
/**
* Set counter to start from 1 and go till desired constant number
* Rolling two separate dices and storing values in dice1 & dice 2 respectively
*/
for (counter=1; counter<=THOUSAND;counter++){
dice1=rollDice.nextInt(6) + 1;
dice2=rollDice.nextInt(6) + 1;
// If statement to check if values are the same or not
if (dice1==dice2){
// IF values are same then go into for loop and store value in array element
for (int i=1; i<=6; i++){
if (dice1 == i && dice2 == i){
// add value for the number displayed into the array
diceValue [i] += 1;
}
}
}
}
// Display results totals of paired rolls
for (int a=1; a<diceValue.length; a++){
System.out.println(" You rolled set of " + a + " " + diceValue[a] + " times");
}
}
public static void welcome () {
System.out.println("welcome to dice world!");
}
}