【发布时间】:2015-09-08 02:52:02
【问题描述】:
我在这里不知所措。
我有这个家庭作业,我必须让用户输入 10 个数字,将它们放在一个数组中,并找出哪些输入的数字是唯一的。
这是我现在的工作流程:输入数字> 如果之前没有输入数字,则存储在数组中;如果之前输入过数字,忽略>显示输入的数字>显示唯一的数字
例如:输入 1 2 3 5 1 2 4 6 会找到唯一的数字并显示“1 2 3 4 5 6”
到目前为止,我的代码如下所示:
public class HwChapter6 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
int[] count = new int[10];
int number = 0;
int x = 0;
boolean unique = false;
int length = count.length;
System.out.println("Insert 10 single digit numbers in any order your heart desires:");
for (int i = 0; i < count.length; i++) {
count[i] = input.nextInt();
number = count[i];
for (int j = 0; j < count.length; j++) {
感谢大家的帮助。
【问题讨论】:
-
您违反了您的计划:“* 如果之前没有输入数字,则存储在数组中;*”。您将来自用户的任何内容存储在数组中。
-
你需要做的是在存储到数组之前检查..如果(theValue不在数组中)那么我在这里向数组添加值