0
I am getting an error : bad operand types for binary operator '<' if ( x < 18) { first type: "Scanner" , second type : "int"
i used this code....😣😣 import java.util.Scanner; public class Condition { public static void main(String [] args) { Scanner x = new Scanner(System.in); if (x <18) { System.out.println("Welcome") } } } I asked my cousin who is in ACCENTURE...he said i need to define the variable ... AND I AM A ROOKIE....AND STARTED LEARNING 14 HRS AGO..
7 odpowiedzi
+ 8
You missed a line:
int input = x.nextInt();
or something like that after the line with the Scanner.
Then correct:
- Missing space between String[] and args
- Syatem -> System
- Missing semicolon after the println statement
+ 6
If it was perfect it would run ;)
+ 4
import java.util.Scanner;
public class Condition {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt(); // get an int from the input stream
if (x < 18) { // x value was not set as an int, but was an InputStream object
System.out.println("Welcome"); // Typo plus missing semicolon
}
}
}
+ 2
tashi that is my typing error..now...but in code its perfect
+ 1
not working😥😥
+ 1
Its working...!!!!🙌🙏🙏🙌🙌