JAVA随机出50以内数_java如何count数字出现的次数啊?意思就是如何return一个50以内的random数组中10到20的所有数,然后计算10到20的数的出现次数.Takesthearra...

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}

}

即可

追问:

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都可以这样处理。

作业帮用户

2016-12-08

举报

6c0a0adef10d1043fa4f41a7897345ed.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值