0

Java scanner

Teacher t = new Teacher(1001, "john" , 28); Teacher t2 = new Teacher(1002, "rose", 26); Instead of this statement...how to accept these values using the scanner (need to accept values from user and pass it into an object)

3rd Aug 2019, 5:18 PM
Sreejith P
Sreejith P - avatar
2 ответов
+ 2
Scanner scan = new Scanner(System.in); Teacher t = new Teacher(scan.nextInt(), scan.next() , scan.nextInt()); Teacher t2 = new Teacher(scan.nextInt(), scan.next() , scan.nextInt()); now input can be accepted as follows in the input box: 1001 john 28 1002 rose 26
3rd Aug 2019, 5:50 PM
Jake
Jake - avatar
0
Even better if you prompt users using Jake 's code. System.out.println("teacher name: "); Etc
3rd Aug 2019, 8:39 PM
HNNX 🐿
HNNX 🐿 - avatar