How can I make it read the counts of 0\'s -9\'s from an index of100 generating b
ID: 3614778 • Letter: H
Question
How can I make it read the counts of 0's -9's from an index of100 generating between 0-9? public class CountNumber { public static void main(String[] args) {// declare an integer array with 10 elements int [] myScore = new int[100]; int i; // initialize an array with random numbers for (i = 0; i < myScore.length; i++) myScore[i] = (int)( Math.random() *10); // print an array for (i = 0; i < myScore.length; i++) System.out.println("myScore[" + i +"]= " + myScore[i]); // count 1's to 9's using array elements as indices int count[] = new int [2]; for (i = 0; i < myScore.length; i++) count[myScore[i]%2]++; System.out.println("The number of zeros = " + count[0]); System.out.println("The number ofThe number of twos = " + count[2]); System.out.println("The number of threes = " +count[3]); System.out.println("The number of fours = " + count[4]); System.out.println("The number of fives = " + count[5]); System.out.println("The number of sixes = " + count[6]); System.out.println("The number of sevens = " +count[7]); System.out.println("The number of eights = " +count[8]); System.out.println("The number of nines = " + count[9]); System.out.println("Done!"); } }
How can I make it read the counts of 0's -9's from an index of100 generating between 0-9? public class CountNumber { public static void main(String[] args) {
// declare an integer array with 10 elements int [] myScore = new int[100]; int i; // initialize an array with random numbers for (i = 0; i < myScore.length; i++) myScore[i] = (int)( Math.random() *10); // print an array for (i = 0; i < myScore.length; i++) System.out.println("myScore[" + i +"]= " + myScore[i]); // count 1's to 9's using array elements as indices int count[] = new int [2]; for (i = 0; i < myScore.length; i++) count[myScore[i]%2]++; System.out.println("The number of zeros = " + count[0]); System.out.println("The number ofThe number of twos = " + count[2]); System.out.println("The number of threes = " +count[3]); System.out.println("The number of fours = " + count[4]); System.out.println("The number of fives = " + count[5]); System.out.println("The number of sixes = " + count[6]); System.out.println("The number of sevens = " +count[7]); System.out.println("The number of eights = " +count[8]); System.out.println("The number of nines = " + count[9]); System.out.println("Done!"); } }
Explanation / Answer
// count 1's to 9's using array elements as indices int count[] = new int [10]; for (i = 0; i < myScore.length; i++) count[myScore[i]%10]++;Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.