125k views
5 votes
Can java scanner not take in a negative input?

User Nassif
by
3.9k points

1 Answer

5 votes

Answer:

It can take a negative input

Step-by-step explanation:

When you declare a variable in Java and you get your input via Scanner library; the Scanner library will accept the input irrespective of whether it's negative or not.

Take for instance, the following segment

Scanner input = new Scanner(System.in);

int userinput = input.nextInt()

Irrespective of whether userinput is negative or positive, it'll accept it.

User Yvonnezoe
by
3.9k points