+ 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.
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) {
}
+ 3
equals method use to compare String. To check greater than or less than use > or < like a > b or a < b
+ 1
AJ #Infinity Love Thank you. I now know what that type of code does. I have never really fully understood it untill now.
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?
0
You forgot the reading-step, this code ignores any input...
Hint: scanner.next*