keko4201
01-27-2005, 08:42 PM
hey guys hows it goin.ok im workingo n my first project, now im not looking for u guys to do my code, cause i did it already, theres just a couple things im not understanding on how to get.
ok i have to make a program that rolls a die 1000 times, and stores the result in an array. this is wha he wants the out put to look like.
/////////////////////////////////////////////////////////////////////
Most frequent value: 4 (186 rolls)
Least frequent value: 2 (143 rolls)
Frequencies:
1: 184 rolls, 18.4%
2: 143 rolls, 14.3%
3: 154 rolls, 15.4%
4: 186 rolls, 18.6%
5: 181 rolls, 18.1%
6: 152 rolls, 15.2%
/////////////////////////////////////////////////////////////////////
ok, so thats how he wnats it, but i cant get it like that cause i cant figure out how to get the hiest frequenci numbers. i can get the amount, but not the specific number. heres wha i mean, this is my output.
/////////////////////////////////////////////////////////////////////
Most Frequent Value 177(see, i can get 177, but not the numer it was)
least Frequent Value 155 (same thing for this)
1 = 166
2 = 155
3 = 161
4 = 177
5 = 167
6 = 174
HOW DO I GET THE NUMBER DIE, THAT WAS ROLLED THE MOST? HELP
////////////////////////////////////////////////////////////////////
ok, now here is my code, i dont know if its any good, so maybe u guys can look at it and make suggestions, its not a lot, just a couple of loops.
/////////////////////////////////////////////////////////////////////
/*
* project.java
*
* Created on January 27, 2005, 7:19 PM
*/
/**
*
* @author Me
*/
public class project {
/** Creates a new instance of project */
public project() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int[] nums = new int[1000];
int[] sides = {1,2,3,4,5,6};
int[] count = new int[6];
for(int j = 0; j<nums.length; j++){
int rolls = (int)(6 * Math.random() + 1);
nums[j] = rolls;
}
int i = 0;
for(int j = 0; j<nums.length; j++){
if(nums[j]==sides[i]){
count[0]++;
}
if(nums[j]==sides[1]){
count[1]++;
}
if(nums[j]==sides[2]){
count[2]++;
}
if(nums[j]==sides[3]){
count[3]++;
}
if(nums[j]==sides[4]){
count[4]++;
}
if(nums[j]==sides[5]){
count[5]++;
}
}
int large = count[0];
int small = count[0];
for(int j = 1; j<count.length; j++){
if(count[j]<small){
small = count[j];
}
if(count[j]>large){
large = count[j];
}
}
System.out.println("Most Frequent Value " + (large));
System.out.println("least Frequent Value " + (small));
int c = 1;
for(int j = 0; j < count.length; j++){
System.out.println(c + " = " + count[j]);
c++;
}
}
}
ok i have to make a program that rolls a die 1000 times, and stores the result in an array. this is wha he wants the out put to look like.
/////////////////////////////////////////////////////////////////////
Most frequent value: 4 (186 rolls)
Least frequent value: 2 (143 rolls)
Frequencies:
1: 184 rolls, 18.4%
2: 143 rolls, 14.3%
3: 154 rolls, 15.4%
4: 186 rolls, 18.6%
5: 181 rolls, 18.1%
6: 152 rolls, 15.2%
/////////////////////////////////////////////////////////////////////
ok, so thats how he wnats it, but i cant get it like that cause i cant figure out how to get the hiest frequenci numbers. i can get the amount, but not the specific number. heres wha i mean, this is my output.
/////////////////////////////////////////////////////////////////////
Most Frequent Value 177(see, i can get 177, but not the numer it was)
least Frequent Value 155 (same thing for this)
1 = 166
2 = 155
3 = 161
4 = 177
5 = 167
6 = 174
HOW DO I GET THE NUMBER DIE, THAT WAS ROLLED THE MOST? HELP
////////////////////////////////////////////////////////////////////
ok, now here is my code, i dont know if its any good, so maybe u guys can look at it and make suggestions, its not a lot, just a couple of loops.
/////////////////////////////////////////////////////////////////////
/*
* project.java
*
* Created on January 27, 2005, 7:19 PM
*/
/**
*
* @author Me
*/
public class project {
/** Creates a new instance of project */
public project() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int[] nums = new int[1000];
int[] sides = {1,2,3,4,5,6};
int[] count = new int[6];
for(int j = 0; j<nums.length; j++){
int rolls = (int)(6 * Math.random() + 1);
nums[j] = rolls;
}
int i = 0;
for(int j = 0; j<nums.length; j++){
if(nums[j]==sides[i]){
count[0]++;
}
if(nums[j]==sides[1]){
count[1]++;
}
if(nums[j]==sides[2]){
count[2]++;
}
if(nums[j]==sides[3]){
count[3]++;
}
if(nums[j]==sides[4]){
count[4]++;
}
if(nums[j]==sides[5]){
count[5]++;
}
}
int large = count[0];
int small = count[0];
for(int j = 1; j<count.length; j++){
if(count[j]<small){
small = count[j];
}
if(count[j]>large){
large = count[j];
}
}
System.out.println("Most Frequent Value " + (large));
System.out.println("least Frequent Value " + (small));
int c = 1;
for(int j = 0; j < count.length; j++){
System.out.println(c + " = " + count[j]);
c++;
}
}
}