public class Demo {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in)
System.out.println("请输入一个明巧谈宽拦整数")
int x = scan.nextInt()
System.out.println("输入的证激碰书是:"+x)
}
下面是我刚写的代渣睁码,实现的方法对你有帮助public class Test1 {
public static void main(String[] args) {
int[] counts = new int[20]
for(int i = 0i <20i++){
counts[i] = (int)(Math.random() * 10)//随稿银机0到9之间的整数
System.out.print(counts[i] + " ")
}
System.out.println()
int [] number = check(counts)
int [] newnumber = new int[10]
int length = 9
for(int k = 0k <10k++){
newnumber[k] = number[length]
length--
}
String output = ""
for(int j = 0 j <10j++){
if(newnumber[j] != 0)
output += j + " appear " + newnumber[j] + ((newnumber[j] == 1) ? " time\n" : " times\n")
}
System.out.println(output)
}
//统键梁宴计每个数出现的次数
public static int[] check(int[] counts){
int[] number = new int[10]
for(int i = 0i <20i++)
number[9 - counts[i]]++
return number
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)