Ransford Anderson
Ransford Anderson

Reputation: 39

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

Upvotes: 0

Views: 1509

Answers (1)

Gaur93
Gaur93

Reputation: 695

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

Upvotes: 2

Related Questions