java 如何count 数字出现的次数啊? 还有就是这个什么意思啊?怎么做呢? 来人帮帮忙啊! 谢谢啦

意思就是如何return一个50以内的random数组中10到20的所有数,然后计算10到20的数的出现次数。Takesthearraycreatedinitem#5,a... 意思就是 如何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)
{
int [] numarray= new int [50];
for(int i=0;i<numarray.length;i++)
{
numarray[i]=(int)(Math.random()*50);

count(numarray);

displaycount(count);
}
}
public static void count(char[] numarray)
{
int [] count= new int [50];
for(int i=0;i<numarray.length,i++)
count[numarray[i]-'10']++;
}

public static void displaycount(int[] count)
{
for(int i=0;i<count.length;i++)
{
if ((i+1)%10==0)
System.out.println(count[i] +"h "+(char)(i+'0'));
else
System.out.print(count[i] +"h "+(char)(i+'0')+" ");
}
}
里面问题可能较多,希望谁写个正确的,但思路差不多和这个一样的,谢谢啦
展开
 我来答
flyingFish211
2011-07-04 · TA获得超过2.1万个赞
知道大有可为答主
回答量:1.5万
采纳率:50%
帮助的人:1.2亿
展开全部
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 {

public static void main(String[] args) {
int[] numarray = new int[50];
int[] count = new int[11]; //0~10, 1~11, 2~12

for (int i = 0; i < numarray.length; i++) {
numarray[i] = (int) (Math.random() * 50);
}

count(numarray, count);
displaycount(count);
}

public static void count(int[] numArray, int[] count){
for(int i = 0; i < numArray.length;i++){

if(numArray[i] == 20){
count[10] = count[10]+1;
}else if(numArray[i] >= 10 && numArray[i] < 20){
count[numArray[i]%10] = count[numArray[i]%10] + 1;
}
}

}

public static void displaycount(int[] count) {
for (int i = 0; i < count.length; i++) {
System.out.println((i + 10) + ": " + count[i]);
}
}
}

即可
更多追问追答
追问
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. 跟之前要count的数字有关系吗? 用ASCII去对比吗? 不知道怎么对比啊!
printOneInLine(parameters)
Pass the array created in item 7 to print each word of the message in a line.
我想print一个表,因为还有十个随机数,倒数 。可是现在的数字是一路下去求赐教!
追答
1) 没有关系,这个是你定义了一个256长度的字符数组,然后你输入了10个字符,就返回10, 输入15就返回15;
2)不明白
pkzahc
2011-07-04 · TA获得超过444个赞
知道小有建树答主
回答量:308
采纳率:0%
帮助的人:0
展开全部
//假设你要判定的数字是int[] arr;
int[] temp = new int[10];
for(int i = 0;i<arr.length;i++){
if(arr[i]>=10 && arr[i]<20){
temp[i-10]++;
}
}
最后这个数组temp中的值就是arr中10-20出现的次数了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
lpdwaini258
推荐于2018-04-06 · TA获得超过1254个赞
知道小有建树答主
回答量:414
采纳率:100%
帮助的人:167万
展开全部
import java.util.Random;
public class RandomTest {
int count=0;
public static void main(String[] args) {
new RandomTest().count(50);
}
public int count(int num){
int[] numarray=new int [num];
Random rd = new Random();
for(int i=0;i<numarray.length;i++){
numarray[i]=rd.nextInt(num);
if (numarray[i]<=20&&numarray[i]>=10){
count++;
System.out.println(numarray[i]);
}
}
return count;
}
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式