0
Please correct my code, thank you
please let me know where is the problem! import java.util.Scanner; class program{ public static void main(String args[]){ int age,money; System.out.println("enter your age"); Scanner a = new Scanner(System.in); age = a.nextInt(); System.out.println("enter money you have"); Scanner m = new Scanner(System.in); money = m.nextInt(); if( age>= 18 && money>500){ System.out.println("welcome"); } else {System.out.println("error");} } }
3 Respostas
+ 4
Yes, single scanner is enough for all data types. You'll just have to call different methods for different data types. (like nextInt() for int, nextDouble() for double etc.)
Example code: https://code.sololearn.com/cWOQlJ1re4p8/#java
Reference on multiple scanners: https://stackoverflow.com/questions/29053580/cannot-use-multiple-scanner-objects-in-java/29053677
+ 3
Use one scanner for all inputs. Change the line of money's input to:
money = a.nextInt();
Also remove the declaration of m. :)
0
can't we call another scanner with defferent variable in the same sintax? is that a single scanner enough for all data types? thanks again for clarifying.