0

What's wrong in my code? Why is it giving error?

import java.util.Scanner; public class check{ public static void main(String[]args){ boolean a; Scanner a=new Scanner(System.in); System.out.println(a.nextBoolean()); if (a==0) System.out.println("Fail"); else System.out.println("Pass"); } }

18th Oct 2018, 1:34 PM
shantanu sontakke
shantanu sontakke - avatar
1 Antwort
+ 1
you're using scanner in wrong way, you can consider scanner used as utilities to get an input, not store the input. so you need to create another variable to store them. and dont use same name for 2 different variable. boolean x; x = a.nextBoolean(); then you can use x for your if condition
18th Oct 2018, 1:54 PM
Taste
Taste - avatar