时间:2021-07-01 10:21:17 帮助过:49人阅读
import java.util.Scanner; //在排序数组中,找出给定数字的出现次数.比如 [1, 2, 2, 2, 3] 中2的出现次数是3次。 public class CiShu { public static void main(String args[]) { int[] nums = new int[] { 1, 2, 2, 2, 2, 3, 3, 3, 5, 5 }; Scanner cin =
import java.util.Scanner;
//在排序数组中,找出给定数字的出现次数.比如 [1, 2, 2, 2, 3] 中2的出现次数是3次。
public class CiShu {
public static void main(String args[]) {
int[] nums = new int[] { 1, 2, 2, 2, 2, 3, 3, 3, 5, 5 };
Scanner cin = new Scanner(System.in);
int a = cin.nextInt();
int i = 0;
while (nums[i] <= a) {
i++;
if (i > nums.length - 1)
break;
}
i--;
System.out.println(i);
int result = 0;
while (nums[i] == a) {
i--;
result++;
if (i < 0)
break;
}
System.out.print(result);
}
}