java 如何count 数字出现的次数啊?意思就是 如何return 一个50以内的random数组中 10到20 的所有数,然后计算10到20的数的出现次数.Takes the array created in item#5,and counts how many times each number occurred in the
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/28 10:59:17
java 如何count 数字出现的次数啊?意思就是 如何return 一个50以内的random数组中 10到20 的所有数,然后计算10到20的数的出现次数.Takes the array created in item#5,and counts how many times each number occurred in the
java 如何count 数字出现的次数啊?
意思就是 如何return 一个50以内的random数组中 10到20 的所有数,然后计算10到20的数的出现次数.
Takes the array created in item#5,and counts how many times each number occurred in the array,and then print the result.
For example:if the given array is {12,11,15,12,11,12} then the output should be
11 occurs = 2
12 occurs = 3
12 occurs = 1
这个有点迷糊:
Create an array of 256 characters ,and read a message character by character from keyboard and store them in the array up to 256 symbols.The method should return number of the characters stored in the array.
我的code:
public static void main(String[] args)
\x05{
\x05int [] numarray= new int [50];
\x05\x05for(int i=0;i
java 如何count 数字出现的次数啊?意思就是 如何return 一个50以内的random数组中 10到20 的所有数,然后计算10到20的数的出现次数.Takes the array created in item#5,and counts how many times each number occurred in the
Create an array of 256 characters ,and read a message character by character from keyboard and store them in the array up to 256 symbols.The method should return number of the characters stored in the array.
这个是让你统计实际放入数组的字符个数呢.
Takes the array created in item#5,and counts how many times each number occurred in the array,and then print the result.
For example:if the given array is {12,11,15,12,11,12} then the output should be
11 occurs = 2
12 occurs = 3
12 occurs = 1
----------------------
public class Cat {
\x05public static void main(String[] args) {
\x05\x05int[] numarray = new int[50];
\x05\x05int[] count = new int[11]; //0~10,11,12
\x05\x05
\x05\x05for (int i = 0; i < numarray.length; i++) {
\x05\x05\x05numarray[i] = (int) (Math.random() * 50);
\x05\x05}
\x05\x05
\x05\x05count(numarray,count);
\x05\x05displaycount(count);
\x05}
\x05public static void count(int[] numArray,int[] count){
\x05\x05for(int i = 0; i < numArray.length;i++){
\x05\x05\x05
\x05\x05\x05if(numArray[i] == 20){
\x05\x05\x05\x05count[10] = count[10]+1;
\x05\x05\x05}else if(numArray[i] >= 10 && numArray[i] < 20){
\x05\x05\x05\x05count[numArray[i]%10] = count[numArray[i]%10] + 1;
\x05\x05\x05}
\x05\x05}
\x05
\x05}
\x05public static void displaycount(int[] count) {
\x05\x05for (int i = 0; i < count.length; i++) {
\x05\x05\x05System.out.println((i + 10) + ":" + count[i]);
\x05\x05}
\x05}
}
即可