简体   繁体   English

无法键入Java控制台

[英]Not able to type into java Console

My console will not let me type into it. 我的控制台不允许我键入它。 I am not sure if this is a problem with my code or the program itself. 我不确定这是否与我的代码或程序本身有关。

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);
}
}

Your for loop is never executed. 您的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