0

Take inputs given

Is there a way to take how many inputs are given to you in Java. For example, I use Scanner to take multiple inputs from the user (separated by ENTER) and use a for-loop to go through each other. I dont know what to set my max as, however, because I don't know how many inputs I will receive: for (int i = 1; i <= ?????; i++) { //output each input }

6th Apr 2019, 12:26 AM
koala 🐨
koala 🐨 - avatar
1 Réponse
+ 1
Have a look at the methods available in the Scanner class - it could be that you have a while ( scanner.hasNext() ) loop and then use an appropriate scanner next method to get input (nextLine() maybe) https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
6th Apr 2019, 3:11 PM
Jenine