Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Netbeans Array help

Have Programming Question? Ask it here!
 
 
 


Candice Weatherman
Netbeans Array help
2 Answer(s)      3 years and 4 months ago
Posted in : Java Beginners


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!


Advertisement
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... of rolls possible within the array Help plese!   Hi Friend, Try... array to tally the actual combinations of rolls. A roll of 2 and 7 would
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
Advertisements
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 punithap@gmail.com so i can contact u personnaly for help
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
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... need help from this part on. I need that part corrected and add a portion..."'s that exceeded that number. Any help I would greatly appreciate. Thank you
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
NetBeans
NetBeans  why Netbeans IDE is not commonly used Today by most of the companies
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
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
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
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
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...[] array() The array() method returns int array based on int buffer
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 array based
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
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...; short[] array() The array() method returns short array based
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...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
webservice in Netbeans
.. im using netbeans version 6.9.1 .. pls help me out... regards-- Harish Kumar
EJB with NetBeans
EJB with NetBeans  I am very new in Ejb and with very few knowledge about it. I have download NetBeans (7.01) and GlassFish (3.01). But, as I have... help me by giving a step by step procedure how to run it . Or can anybody suggest
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
RMI and netbeans
RMI and netbeans  how to use Rmi in netbeans? i want to connect to a server machine which is holding my application and need to identify the systems connected in LAN with it and get the IP address from it i wnt to use netbeans
java netbeans
java netbeans  i am making project in core java using Netbeans. Regarding my project i want to know that How to fetch the data from ms-access... using netbeans
java netbeans
java netbeans  i am making project in core java using Netbeans. Regarding my project i want to know that How to fetch the data from ms-access... using netbeans
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
netbeans program
netbeans program  Hi. could someone build this for me in netbeans please :) You are required to create a basic library management system for use.../array of objects of this type. Bonus marks will be given for ensuring
netbeans library
netbeans library  Hi could someone build a program in netbeans for a book library please.The program should provide a menu of options to work with the library, including: 1) Adding a new item to the library 2) Viewing all stock
netbeans library
netbeans library  Hi could someone build a program in netbeans for a book library please.The program should provide a menu of options to work with the library, including: 1) Adding a new item to the library 2) Viewing all stock
struts-netbeans - Framework
struts-netbeans  hai friends please provide some help "how to execute struts programs in netbeans IDE?" is requires any software or any supporting files to execute this. thanks friends in advance
jsp netbeans javascript
jsp netbeans javascript  hi to all; I'm debutante in JSP netbeans, please help me to realize my application I have some difficulties: 1 - page... nothing is changed.) 2-how iserer date in oracle 10g database via JSP netbeans
NetBeans IDE
NetBeans IDE         The NetBeans IDE, product of Sun Microsystems, is a free, open-source.... NetBeans IDE supports developers providing all the tools needed to create all
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
RMI in netbeans 6.5
RMI in netbeans 6.5  runing client in RMI using netbeans 6.5
Netbeans GUI Ribbon
Netbeans GUI Ribbon  how to create ribbon task in java GUI using netbeans
help
help  i need ajava code for compressing files using huffman algorithm (run on netbeans correctly
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
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
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
hibernate on netbeans - Hibernate
hibernate on netbeans  is it possible for me to run the hibernate program on Netbeans IDE
JNDI names in netbeans
JNDI names in netbeans  how to create a JNDI names in netbeans
connect netbeans with oracle
connect netbeans with oracle  how to connect netbeans with oracle   Hi Friend, Please visit the following link: http://www.roseindia.net/jsf/visual-jsf.shtml Here you will find the steps to connect netbeans
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
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
"The folder name is not valid" netbeans
"The folder name is not valid" netbeans  "The folder name is not valid" while crating a jsp,html or any page in netbeans
RMI Program in netbeans
RMI Program in netbeans  pls give me an idea for how to run RMI program in netbeans with detailed example
 

 

 

DMCA.com