永发信息网

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

答案:3  悬赏:60  手机版
解决时间 2021-04-27 15:49
java 如何count 数字出现的次数啊? 还有就是这个什么意思啊?怎么做呢? 来人帮帮忙啊! 谢谢啦
最佳答案
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[i]=rd.nextInt(num);
if (numarray[i]<=20&&numarray[i]>=10){
count++;
System.out.println(numarray[i]);
}
}
return count;
}
}
全部回答
//假设你要判定的数字是int[] arr;
int[] temp = new int[10];
for(int i = 0;i if(arr[i]>=10 && arr[i]<20){
temp[i-10]++;
}
}
最后这个数组temp中的值就是arr中10-20出现的次数了。
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)不明白追问就是像一个表一样,本来是
number
1
2
3
4
5
reverse
5
4
3
2
1。
我想让他成为
number reverse
1 5
2 4
3 3
4 2
5 1追答存在数组里面的还是? 如果是数组
int nums[] = {1, 2, 3, 4, 5};
for(int i = nums.length -1; i >= 0; i--){
System.out.println(nums[i]);
}
即可。数组, list都可以这样处理。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
a=2b c=5a(a≠0) 6a+2b-c除以a-4b+c
金三角超市地址有知道的么?有点事想过去
黄家驹有一首歌用粤语唱有叉叉叉唱的,知道的
钱串子花怎么繁殖,请问这个钱串怎么干干扁扁
许嵩的头型叫什么、头发流到哪里能整成像他一
飞车现在还有签王之王的任务吗?
老是有我不认识的人在我的农场和牧场里去偷我
能不能一下子把好友全删了?
生物防治就是利用________?来防治________.
一次性医用口罩怎么佩戴?
在生活中吃什么东西有助于减肥
怎么修改QQ音速家族的介绍
一个手机看哪些主要参数来评价它的性能优劣
巧手饰品这个地址在什么地方,我要处理点事
人为什么活的很累?
推荐资讯
如何摆脱抑郁寡欢
DNF最近这几天怎么老是网络中断?
A peur de l'avenire什么意思
一把普通古琴,一般多少钱
怎样在最短的时间内把痘痘取出的最干净?
巴州区职业教育中心地址在哪,我要去那里办事
酷狗音乐盒里有一首东方神起的歌《月亮的眼泪
PS2龙珠电光火石3出现这种现象如可解决
八一路/帅乡大道二段(路口)在哪里啊,我有事
纤艺彩妆美甲地址在哪,我要去那里办事
新飞飞50级以上刺客装备如何打?
宁波昊欣汽车服务有限公司地址在哪,我要去那
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?