Problems With Some Inputs - Java

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
Kenpachi24
New poster
Posts: 20
Joined: Wed Oct 30, 2013 7:06 pm

Problems With Some Inputs - Java

Post by Kenpachi24 » Wed Jan 29, 2014 1:52 am

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)???????

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Problems With Some Inputs - Java

Post by brianfry713 » Wed Jan 29, 2014 10:36 pm

You could use StringTokenizer
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Java”