我已经写存储一些值一个java PROG:爪哇 - 在阵列计数数字
public class array05 {
public static void main(String[] args) {
//placement of value
int arryNum[] = {2,3,4,5,4,4,3};
//placement of index, to start at 0
for(int counter=0;counter<arryNum.length;counter++){
System.out.println(counter + ":" + arryNum[counter]);
}
}
}
其中产生这样的输出:
0:2
1:3
2:4
3:5
4:4
5:4
6:3
,现在我需要在此输出#1中计数数字。 输出#2应该是这样的:
1:0
2:1
3:2
4:3
5:1
这意味着它计数ONE 2,TWO 3,三4,并且只有一个5.
我不知道如何编写输出2的代码。 是否需要二分法搜索?
有人可以开灯吗?
问题的陈述是否包括在阵列中的数字有限制吗?也就是说,他们都保证少于10? –
http://stackoverflow.com/q/8098601/1007273 – hovanessyan
你试图实现计数排序。 –