逐一搜索数组元素
You could just use a for loop, like this: import java.util.Arrays; /**来自 时代Java - N o w J a v a . c o m**/ public class Main { public static void main(String[] args) { int[] lotto = new int[6]; for (int i = 0; i < 6; i++) lotto[i] = (int) (Math.random() * 100) + 1; Arrays.sort(lotto); int lucky = 13; int foundAt = -1; for (int i = 0; i < lotto.length; i++) if (lotto[i] == lucky) foundAt = i;//来自 时代Java - nowjava.com if (foundAt > -1)