【发布时间】:2014-09-30 23:21:11
【问题描述】:
我需要找到数组中的最后一个数字,看看它是否等于零。这是我正在使用的代码;
import java.util.Scanner;
public class NrOccurrence
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter the integers between 1 and 100: ");
int[] numbers = new int[100], times = new int[100];
boolean zero = false;
while (zero == false)
{
for (int a = 0; a <= numbers.length; a++)
{
numbers[a] = scan.nextInt();
times[a]++;
if (numbers.equals(0))
{
zero = true;
}
}
}
for (int b = 0; b <= numbers.length; b++)
{
System.out.println(numbers[b] + " occurs " + times[b] + " times");
}
scan.close();
}
}
【问题讨论】:
-
你有什么问题?
-
不是你的问题——但我感觉
times[a]++;应该写成times[numbers[a]]++;