Problems With Some Inputs - Java
I've always done data entry as follows:
InputStreamReader isr= new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(isr);
int num=Integer.parseInt(br.readLine()); //number
String linea=br.readLine(); //cadena
arreglo=linea.split(" ");// case as: 8 8 8 8 8 8
but I have encountered problems where this form of input not work; example
8
1 2 3 3 4 5 7 8
My question is:
what is the proper way to read this data in java? (number by number and so avoid spaces or some traps)???????
Problems With Some Inputs - Java
Moderator: Board moderators
-
- New poster
- Posts: 20
- Joined: Wed Oct 30, 2013 7:06 pm
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Problems With Some Inputs - Java
You could use StringTokenizer
Check input and AC output for thousands of problems on uDebug!