How to make the output side by side. I need HELP!

• March 17th, 2013, 08:17 PM
JAVAHELPP
How to make the output side by side. I need HELP!
Okay so I have to find the number of times 2 die land on 2-12 /and the percentage of getting a 1 a 2 and so on rolling it 10million times.

So far I have this:
Code :

```import java.util.Random; public class MonteCarlo {   /** * @param args */ public static void main(String[] args) {       { Random randomNumbers = new Random(); // Generates random numbers int[] array = new int[ 13 ]; // Declares the array int dice1; int dice2;     //Roll the die 36,000 times for ( int roll = 1; roll <=10000000; roll++ ) { int die1 = randomNumbers.nextInt ( 6 )+ 1; int die2 = randomNumbers.nextInt ( 6 )+ 1; int total = die1 + die2; ++array[total];   }     // outputs array values               int nRolls = 100, nDice = 6; // default values       nRolls = 10000000; //10,000,000 rolls of the dice nDice = 6; // six sides of the dice int minSum = 2, maxSum = 2 * nDice; //lowest sum of dice is two. Max sum is 2 times the number of sides. minSum= 2, maxSum=12 int[] Prop = new int[maxSum - minSum + 1];   Random rand = new Random(); //random for (int iter = 1; iter <= nRolls; iter++) { int throw1 = 1 + rand.nextInt(nDice), throw2 = 1 + rand.nextInt(nDice); int sum = throw1 + throw2; Prop[sum - minSum]++; }   System.out.println("Number of rolls: " + nRolls + " on a six sided dice"); // Using int nRolls System.out.println("Number of sides of the dice: " + nDice); //Usin int nDice System.out.println("Sum of Dice Percentage Number Of Times Rolled"); // created space so it creates space in the output for (int i = 0; i < Prop.length; i++) { System.out.println(String.format(" %2d %5.2f%%", i + minSum, Prop[i] * 100.0 / nRolls)); // System.out.println(" " + (i+minSum) + " " + (hist[i]*100.0/nRolls); }{ for ( int face = 2; face < array.length; face++ ) System.out.printf( "%4d%10d\n", face, array[ face ] ); } } // end main   }} // end class DiceRollin```

The output is:
Code :

```Number of rolls: 10000000 on a six sided dice Number of sides of the dice: 6 Sum of Dice Percentage Number Of Times Rolled 2 2.78% 3 5.56% 4 8.32% 5 11.11% 6 13.90% 7 16.67% 8 13.88% 9 11.11% 10 8.33% 11 5.55% 12 2.78%   555185 832554 1111462 1389278 1667420 1389082 1111436 832328 554695 277347```

As you can see i do not want the numbers 2-12 again. I need the out put to look like THIS:
Code :

```    Number of rolls: 10000000 on a six sided dice Number of sides of the dice: 6 Sum of Dice Percentage Number Of Times Rolled 2 2.78% 279213 3 5.56% 555185 4 8.32% 832554 5 11.11% 1111462 6 13.90% 1389278 7 16.67% 1667420 8 13.88% 1389082 9 11.11% 1111436 10 8.33% 832328 11 5.55% 554695 12 2.78% 277347```

• March 17th, 2013, 08:32 PM
Norm
Re: How to make the output side by side. I need HELP!
Is the problem with the output that the Number Of Times Rolled is not on the same row with the other two values?

Where do you format the line for printing? Why don't you add that third item to the data that is on the row?
• March 17th, 2013, 09:33 PM
JAVAHELPP
Re: How to make the output side by side. I need HELP!
Sorry i made a mistake in copying my output...It looks like this and i want it changed to what is above.

Output so far:
Code :

```  Number of rolls: 10000000 on a six sided dice Number of sides of the dice: 6 Sum of Dice Percentage Number Of Times Rolled 2 2.77% 3 5.56% 4 8.35% 5 11.13% 6 13.89% 7 16.67% 8 13.89% 9 11.10% 10 8.32% 11 5.55% 12 2.77% 2 278192 3 556866 4 832608 5 1111222 6 1389046 7 1666643 8 1388537 9 1110083 10 832644 11 555531 12 278628```

--- Update ---

Quote:

Why don't you add that third item to the data that is on the row?
I tried doing that but I get errors. I am probably doing it wrong. Please help. Thanks Norm
• March 18th, 2013, 05:53 AM
Norm
Re: How to make the output side by side. I need HELP!
Quote:

but I get errors
Please copy the full text of the error messages and paste it here.

What are the two arrays: (array and Prop) used for? Why do you need two?
• March 18th, 2013, 06:39 AM
Tamilarasi
Re: How to make the output side by side. I need HELP!
you made mistake on your loop. Because you used double for loop
So process completed the first for loop and print the statement after that that will be go to another one.

So print your output using single for loop like below...

Code :

```for (int i = 0; i < Prop.length; i++) { System.out.println(String.format(" %2d %5.2f%% %10d ", i + minSum, Prop[i] * 100.0 / nRolls,array[ i+2 ]));   }```
• March 18th, 2013, 07:49 PM
JAVAHELPP
Re: How to make the output side by side. I need HELP!
Thank you!! I got it now. I don't know why i used a double loop. I'm new to all of this but i get it now.