+ 1

Java Scanner comparision.

“Scanner can not be compared to int.” I have searched this question up and have found the .equals() function. Is there a greater than or less than function? Thanks.

29th May 2020, 11:14 PM
Code214
Code214 - avatar
5 Respuestas
+ 5
Code214 Yes because a is a object of scanner class and you can't compare with integer. To compare get integer value from scanner object like Scanner sc = new Scanner ( System.in); int a = sc.nextInt(); if (a > 2) { }
29th May 2020, 11:44 PM
A͢J
A͢J - avatar
+ 3
equals method use to compare String. To check greater than or less than use > or < like a > b or a < b
29th May 2020, 11:31 PM
A͢J
A͢J - avatar
+ 1
AJ #Infinity Love Thank you. I now know what that type of code does. I have never really fully understood it untill now.
30th May 2020, 12:13 AM
Code214
Code214 - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner a = new Scanner(System.in); if(a>2){ System.out.println("a is greater than 2"); } } } Bad operend types for binary operator. ???????? What does this mean? is this unrealated?
29th May 2020, 11:38 PM
Code214
Code214 - avatar
0
You forgot the reading-step, this code ignores any input... Hint: scanner.next*
29th May 2020, 11:55 PM
Sandra Meyer
Sandra Meyer - avatar