问题描述:

This question already has an answer here:

  • Why does the toString method in java not seem to work for an array

    7 answers

网友答案:

modified code hope my code helps

     Random rand = new Random();
int freq[]=new int[7];

for(int roll = 0; roll<1000; roll++){
    ++freq[1+rand.nextInt(6)];
}

System.out.println("Face\tFrequency");

for(int face=1;face<freq.length;face++){
    System.out.println(face + "\t" + freq[face]);
}

happy coding

网友答案:

You are printing an array to the output and the toString() method of the array is not so readebla that's the problem. If you want to print the elements of the array you should iterate over the array and print the actual element yourArray[index] or you can just use Arrays.toString(yourArray)

相关阅读:
Top