Getting inputs from Scanner
Page 1 of 19 Replies - 110 Views - Last Post: 12 September 2012 - 01:24 PM
#1
Getting inputs from Scanner
Posted 12 September 2012 - 11:45 AM
Replies To: Getting inputs from Scanner
#2
Re: Getting inputs from Scanner
Posted 12 September 2012 - 11:50 AM
#3
Re: Getting inputs from Scanner
Posted 12 September 2012 - 11:52 AM
String input = "1 2 3 4";
Scanner s = new Scanner(input).useDelimiter("\\s*");
Otherwise, if you prompt them 5 times, then you can just use the sc.nextInt() on each input
#4
Re: Getting inputs from Scanner
Posted 12 September 2012 - 11:53 AM
#5
Re: Getting inputs from Scanner
Posted 12 September 2012 - 11:54 AM
This post has been edited by HopelessDev: 12 September 2012 - 11:56 AM
#6
Re: Getting inputs from Scanner
Posted 12 September 2012 - 11:57 AM
HopelessDev, on 12 September 2012 - 02:45 PM, said:
Just read using scan.nextInt() 5 times then scan.nextLine() and ignore what it returns
#7
Re: Getting inputs from Scanner
Posted 12 September 2012 - 12:00 PM
#8
Re: Getting inputs from Scanner
Posted 12 September 2012 - 12:00 PM
HopelessDev, on 12 September 2012 - 02:54 PM, said:
All of the input coming in through scanner will be strings. nextInt will attempt to read the next token in, and convert it to an int for you.
int num1 = sc.nextInt();
#9
Re: Getting inputs from Scanner
Posted 12 September 2012 - 12:10 PM
I forgot to ask something. Whats the best way to not make the user input a number more than N times? Is if statement good enough?
#10
Re: Getting inputs from Scanner
Posted 12 September 2012 - 01:24 PM
|
|

New Topic/Question
Reply



MultiQuote



|