原题是这样的。我一开始写的是:
package homeworks;
import java.util.Scanner;
public class SixPoint3 {
public static void main(String[] args) { System.out.print("Enter the integers between 1 and 100: "); int n = -1; double x = 0; Scanner input = new Scanner(System.in); do{ x = input.nextDouble(); n++; }while(x != 0); final int n1 = n; double[] numbers = new double[n1]; for(int i = 0; i < n1; i++) numbers[i] = input.nextDouble(); for(double u: numbers) System.out.print(u + " "); int[] times = new int[n1]; for(int i = 0; i < n1; i++){ times[i] = 1; for(int j = i + 1; j < n1; j++){ if(numbers[j] == numbers[i]) times[i] ++; } System.out.print(numbers[i] + "occurs" + times[i]); if(times[i] == 1) System.out.print(" time\n"); else System.out.print(" times\n"); } }}
输入的值赋给x计算数组长度后就不能再赋给numbers[i]了。请问各位有没有什么好办法?在这里先谢谢大家了O(∩_∩)O。搜索看见有用ArrayList的,我也没大看明白。