Why is this not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is this not working?

import java.util.Scanner; class dinu { public static void main(String[]args) { Scanner a=new Scanner(System.in); Scanner b=new Scanner(System.in); if(a>b&&a>2) { System.out.println("hi"); } else if(b>a||a==2) { System.out.println("hello"); } } }

7th Feb 2019, 6:09 PM
Dinesh K
Dinesh K - avatar
3 Answers
+ 2
The default input type for "Scanner" is string so for comparison like your code you need to change the data type to Integer .
7th Feb 2019, 6:21 PM
Million Gashawbeza
Million Gashawbeza - avatar
7th Feb 2019, 7:27 PM
Lambda_Driver
Lambda_Driver - avatar
+ 1
You don't need two scanners for input. I think you are trying to compare numbers so you need int variables.
7th Feb 2019, 6:23 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar