简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM