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..

16th Sep 2017, 8:09 PM
Sonu Kumar Jha
Sonu Kumar Jha - avatar
7 Réponses
+ 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
16th Sep 2017, 8:15 PM
Tashi N
Tashi N - avatar
+ 6
If it was perfect it would run ;)
16th Sep 2017, 8:18 PM
Tashi N
Tashi N - avatar
+ 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 } } }
16th Sep 2017, 8:23 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
tashi that is my typing error..now...but in code its perfect
16th Sep 2017, 8:16 PM
Sonu Kumar Jha
Sonu Kumar Jha - avatar
+ 1
not working😥😥
16th Sep 2017, 8:22 PM
Sonu Kumar Jha
Sonu Kumar Jha - avatar
+ 1
Its working...!!!!🙌🙏🙏🙌🙌
16th Sep 2017, 8:26 PM
Sonu Kumar Jha
Sonu Kumar Jha - avatar