0

Why does it give me error? Some explain why i cant store the user input into an int and why i cant use the scanner as a boolen*

public static void main (String args[]){ Scanner y= new Scanner (System.in); System.out.println(y.nextInt()); int z=y; int x= 1; if (z = x){ System.out.println("hello");} else {System.out.println ("nope");} } *even tho im using an if loop. I mean the loop is kinda true/false so maybe the program is reading it as a boolen. Please i need an explanation it would help me alot. Thanks in advance :)

12th May 2019, 3:29 AM
Victor Tonna
Victor Tonna - avatar
4 Antworten
+ 5
Victor Tonna If you plan to show your code in a thread, please make sure that it is void of profanities.
12th May 2019, 3:47 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Line 12: if(z==X). <- double equal to sign = Assignment == Comparison Line no. 7 Scanner y= new Scanner (System.in); z = y.nextInt(); Remove line no. 9 and write line no. 7 and 8 in one line
12th May 2019, 3:45 AM
‎ ‏‏‎Anonymous Guy
0
Also sorry for the strong language . i was testing my self and didnt think i was going to share this code so please dont get offended. Tks :)
12th May 2019, 3:40 AM
Victor Tonna
Victor Tonna - avatar
0
Hatsy Rei yes im sorry. It will not happen agian.
12th May 2019, 4:17 AM
Victor Tonna
Victor Tonna - avatar