簡體   English   中英

無法鍵入Java控制台

[英]Not able to type into java Console

我的控制台不允許我鍵入它。 我不確定這是否與我的代碼或程序本身有關。

import java.util.*;

public class assignment_2 {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    removeDuplicate();
}

public static void removeDuplicate() {
    Scanner input = new Scanner(System.in);
    List<Integer> numberList = new ArrayList<Integer>();
    System.out.println("Enter ten numbers: ");

    for (int i = 0; i == 10; i++) {
        if (numberList.contains(input.nextInt())) {

        } else {
            numberList.add(input.nextInt());
        }
    }

    numberList.forEach(System.out::print);
}
}

您的for循環永遠不會執行。

for (int i = 0; i == 10; i++) { // here i==10 is never true as i=0
                                // so it should be i<10 or i <=10
    if (numberList.contains(input.nextInt())) {

    } else {
        numberList.add(input.nextInt());
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM