+ 1

Java scanner.nextInt() and read.nextInt()

As far as I learned, Scanner scanner = new Scanner(System.in); is a method to ask the user to give input. And to use this input, I should use int number = scanner.nextInt(); But I also saw a method below from practice. int number = read.nextInt(); What's 'scanner.nextInt' and 'read.nextInt', and what do they do?

8th Jun 2021, 11:38 AM
Jay Kay
2 Answers
+ 8
Scanner scanner ^ ^ | | Class object You can name your object anything, maybe read, in, apple anything. And method available in a class, you can use it by object. You can say it's syntax is object.method() https://code.sololearn.com/ckCzk0EfeE1r/?ref=app https://code.sololearn.com/c77mwST3ABMK/?ref=app https://code.sololearn.com/cNi11t7vr6on/?ref=app see line no 6 and 7 .
8th Jun 2021, 11:55 AM
Abhiyantā
Abhiyantā - avatar
+ 2
Rishav Tiwari oh wow. Thank you for the clear answer 👍👍
8th Jun 2021, 12:01 PM
Jay Kay