Netbeans Array help

Netbeans Array help

Ok here is my code-

*
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
import java.util.Random; 
/** 
* 

*/ 
public class ContinueRollDie { 

* @param args the command line arguments
*/
public static void main(String[] args) {
Random randomNumber = new Random();

int[][] frequency = new int[9][9];
int die1 = 0;
int die2 = 0;
for (int roll = 1; roll <= 64000; roll++) {
die1 = randomNumber.nextInt(8) + 1;
die2 = randomNumber.nextInt(8) + 1;
frequency[die1] [die2]++;
}
System.out.printf("%s%16s\n", " Sum", " Frequency");
for (int sum = 2; sum <= 12; sum++) {
System.out.printf("%4d%16d\n", sum, frequency[die1][die2]);


}


}

}

This is what I am trying to get my program to due- using a two-dimensional array to tally the actual combinations of rolls. A roll of 2 and 7 would be different than a roll of 7 and 2. The application should roll the dice 64,000 times.

I are trying to get the application to to tally the actual combination's of rolls possible within the array

Help plese!

View Answers

December 7, 2010 at 5:57 PM

Hi Friend,

Try the following code:

import java.util.Random;
public class ContinueRollDie{
   public static void main(String[] args){
      Random randomNumber = new Random();
      int die1;
      int die2;
      int frequency[] = new int[ 13 ]; 
      for ( int index = 0; index < frequency.length; index++ )
         frequency[ index ] = 0;
           for ( int roll = 1; roll <= 64000; roll++ ) {
         die1 = 1 + randomNumber.nextInt( 6 );
         die2 = 1 + randomNumber.nextInt( 6 );
         frequency[ die1 + die2 ]++;
      } 
       System.out.printf( "%3s%12s\n","Sum", "Frequency" );
         for ( int i = 2; i < frequency.length; i++ ) {
         System.out.printf( "%3d%12d\n", i, frequency[ i ]);
      } 
   } 
}

Hope that it will be helpful for you.

Thanks


December 8, 2010 at 4:44 AM

Thanks for your help but what I need is a two-dimensional array to tally the actual combination's of rolls 2 d array, not 1, thank you so much!









Related Tutorials/Questions & Answers:
Netbeans Array help
Netbeans Array help  Ok here is my code- * * To change this template... array to tally the actual combinations of rolls. A roll of 2 and 7 would... of rolls possible within the arrayADS_TO_REPLACE_1 Help plese!   Hi Friend
HELP WITH ARRAY
HELP WITH ARRAY  Hi i would like this program: public class ArrayApp... that the user input didn't match match with the number in the array boxes.. the output should be "Invalid Input" if it matches the number in the array boxes
Advertisements
Help With an Array
Help With an Array  So what Im trying to do is write an array... trying to do is almost combine the two to create a larger array declaration... not figure out how to finish the code. Please HELP! A) students? names
Help With an Array
Help With an Array  // ******************** // Sales.java // // Reads...] < ) is wrong but I need help from this part on. I need that part corrected... number of "salesperson"'s that exceeded that number. Any help I would greatly
Netbeans Question need help desperately!!
Netbeans Question need help desperately!!   Ok here is my code- public class RollDie2 { public static void main(String[] args) { Random... a two-dimensional array to tally the actual combinations of rolls on 8 sided
java -netbeans help - Java Beginners
java -netbeans help   a simple program in netbeans ide to add two.../mam, i developed frontend with netbeans with buttons and textarea.. am executing... mail id pls pass it to [email protected] so i can contact u personnaly for help
NetBeans
NetBeans  Hi, I am Kundan I have made a project on NetBeans. And now I want to know that how can i run my project without NetBeans IDE,on other PC. Please help me it's important
NetBeans
NetBeans  Hi, I am Kundan I have made a project on NetBeans. And now I want to know that how can i run my project without NetBeans IDE,on other PC. Please help me it's important
Need help in constructing a 2 dimensionla array?
Need help in constructing a 2 dimensionla array?  Construct a 2 dimensional array that for each entry in the array, display the index of the first... array. import java.util.*; public class twoDimension{ public static void main
plz help me to create gui using Java netbeans
plz help me to create gui using Java netbeans  Hi, I am unable to fetch a particular data from DB.I am using netbeans for creating GUI. If I want.... I am unable to fetch the particular data. Plz help me   Hi Friend
please help me how to set up Netbeans for JSP
please help me how to set up Netbeans for JSP   Hi roseindian.net... help me.We are ready to do INDUSTRIAL PROJECT by JSP. Thank you. ERROR.../xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch
please help me to solve this question about array
please help me to solve this question about array  write a program thatt stores vowels (a,e,i,o and u)in an array. Ask the user to enter any character. The program should ignore the case of that character (uppercase or lowercase
NetBeans
NetBeans  why Netbeans IDE is not commonly used Today by most of the companies
Generating Random Numbers to Fill array. Java Beginner needing help!
Generating Random Numbers to Fill array. Java Beginner needing help!  ... methods: // Displays the array permutatedNumbers to the console public void... the permutated array public void generatePermutation(){} Make an array to hold
How to create a long array with the help of long buffer.
How to create a long array with the help of long buffer.  In this tutorial, we will see how to create a long array with the help of long buffer....  long[] array() The array() method returns long
Create a int array with the help of int buffer.
Create a int array with the help of int buffer.  In this tutorial, we will see how to create a int array with the help of int buffer. IntBuffer API...; float[] array() The array() method returns int array based
Create a short array with the help of short buffer.
Create a short array with the help of short buffer.  In this tutorial, we will see how to create a short array with the help of short buffer... capacity.  short[] array() The array() method returns
netbeans
netbeans  In netbeans, there are choices of books with their price. you check the book you wanted then click the purchase.the output should be the book with the price then you will get the total price of the book you purchase.how
netbeans
netbeans  guysss m nt able to opemn ma netbeans ide.. no error msg s coming... wn i installed yesterday one msg came stating about some run time error... sm one plzzzzzz hlp me
cannot find symbol class array queue--plzz somebody help..
cannot find symbol class array queue--plzz somebody help..  import java.util.*; public class Test { public static void main(String[] args) { ArrayQueue<String> q = new ArrayQueue<String>(6); System.out.println
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble... cannot figure out how i can declare a two dimensional array without knowing how... many words he/she types without using an array list.   Thank you. I
Array's
Array's  I have to finish an "order page". that checks 2 dropdown... line at a time, then calculate a total. I know I need to create an array, but I'm having a hard time figuring out the loop. I just need a little help to get
help
help  i need help with this code. write a java code for a method named addSevenToKthElement that takes an integer array, and an integer k as its arguments and returns the kth element plus 7. any help would be greatly
Netbeans program
Netbeans program  I need to write a program that does the following... The TicTacToe class contains a 3x3 two-dimensional array of integers... a two human player game of Tic-Tac-Toe. Using the NetBeans design tool also create
Netbeans Question.
possible within the array. I need 2 arrays. Help plese!ADS_TO_REPLACE_1...Netbeans Question.   Ok here is my code- * * To change this template...]); } } } This is what I am trying to get my program to due- using a two-dimensional array
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
help
help  i need ajava code for compressing files using huffman algorithm (run on netbeans correctly
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend... Scanner(System.in); int array[]=new int[5]; System.out.println("Enter
please please i wanna insertion sort program find calendar to array value (1000,5000,10000), please help me
Insertion sort program find calendar to array value 1000,5000,10000  program find calendar for insertion sort in jfram to array 1000
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
Array
Array  How do i insert elements into an array up to a limit from...("Enter Range: "); int size=input.nextInt(); int array[]=new int[size]; System.out.println("Enter Array Elements: "); for(int i=0;i<
array
array  WAP in java to store 6 element in array P and 4 element in array Q. Produce the third arra y R containing all element from p & q
Java Array declaration
Java Array declaration In this section you will learn how to declare array in java. As we know an array is collection of single type or similar data type. When an array is created its length is determined. An array can hold fixed
Array
Array  can we create an array of size 1 lakh in java programming
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below
array
accepts a pointer to integer which represents an array of integer.After that this method prints the entire of the array numbers to the monitor. include using std::cout; using std::endl; void printArray(int *array, int count
array
array  How to store the results of mysql query in an array... qurey in array: "select distinct(EMPLID)from tblwork where EMPLID not in (select... store the result in array
PHP Array Type
PHP Array Types: In PHP an array is more than just array, it is an ordered map... it as an array, list or vector, hash table, etc.  In associative array a key may... will be truncated as integer. ADS_TO_REPLACE_1 Following examples will help you to learn
unable to display image using html tag in servlet.(image src is in a variable.....). i am using netbeans IDE. plz..........do help
unable to display image using html tag in servlet.(image src is in a variable.....). i am using netbeans IDE. plz..........do help  import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException
PHP Array
Array in PHP Almost every language supports array, which is a collection.... An array could be a collection of similar or dissimilar datatype.  PHP Array Example 1:ADS_TO_REPLACE_1 <?php echo"An array with similar
help
help  i can't answer this question....state 2 different array processing which use loops

Ads