0

Hi i am having issues with my code at the moment as i have been stuck for a while now, i am new to java programming. I want the code output to be from 0-9 not 1-10, my code and output is displayed below:

import java.util.Arrays;

public class RandNumGenerator {

public static int RandInt(){
    double n = Math.random()*10;
    return (int) n;
    }

public static void randTest(int n){
    int [] counts = new int [10];
    int sampleSize = 10000;
    int RandNum = RandInt();

    System.out.println ("Sample Size: " + sampleSize);
    String[] intArray = new String[] {"Value","Count","Expected","Abs Diff","Percent Diff"};
    System.out.println(Arrays.toString(intArray));



    for(int i=0;i<n;i++){
        counts[ RandNum ] = counts[ RandNum ] + 1;
        System.out.println(counts[RandNum]);
        } 
    }

public static void main(String[] args) {
    randTest(10);
    }
}

output is 1-10, not 0-9:

Sample Size: 10000
[Value, Count, Expected, Abs Diff, Percent Diff]
 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
rico99
  • 77
  • 1
  • 3
  • 10
  • Delete `counts[ RandNum ] = counts[ RandNum ] + 1;` – Matt Jul 27 '15 at 21:01
  • @EricJ. Never go with votes, look for all answers. I know lot of questions have best answers which are not accepted nor voted high. – kosa Jul 27 '15 at 21:15

0 Answers0