Integer.parseInt failing 'For input string: "5000"' - java

I'll admit it, I'm stumped. It's not a double. It's not outside of the range of an integer. It's not NAN. It's not a non-integer in any way shape or form as far as I can tell.
Why would I get that error?
Here's the code that causes it:
String filename = "confA.txt";
//Make a new filereader to read in confA
FileReader fileReader = new FileReader(filename);
//Wrap into a bufferedReader for sanity's sake
BufferedReader bufferedReader = new BufferedReader(fileReader);
//Get the port number that B is listening to
int portNum = Integer.parseInt(bufferedReader.readLine());
It fails on that last line, stating:
java.lang.NumberFormatException: For input string: "5000"
Which is the number I want.
I've also attempted
Integer portNum = Integer.parseInt(bufferedReader.readLine());
But that didn't work either. Neither did valueOf().

Most probably there is some unprintable character somewhere in your file line. Please consider the following example (this was tested in Java 9 jshell)
jshell> String value = "5000\u0007";
value ==> "5000\007"
jshell> Integer.parseInt(value);
| java.lang.NumberFormatException thrown: For input string: "5000"
| at NumberFormatException.forInputString (NumberFormatException.java:65)
| at Integer.parseInt (Integer.java:652)
| at Integer.parseInt (Integer.java:770)
| at (#15:1)
Here the string contains the "bell" character at the end. It makes parse to fail while it is not printed in exception text. I think you have something similar. The simpliest way to verify this is to check
String line = bufferedReader.readLine();
System.out.println("line length: " + line.length());
The value other than 4 will support my idea.

I had the same problem. I was reading in a flat file with the Buffered reader and saving the contents as an ArrayList of type String, but on performing an integer.parse when retrieving a string value from the list, I realised that there was a whole lot of garbage in the string read from the file, as I got a java.lang.NumberFormatException.
This was the method I implemented with the code (called from my main method) to solve the problem:
`
// class level
private static final Pattern numericPattern = Pattern.compile("([0-9]+).([\\\\.]{0,1}[0-9]*)");
// in main method after reading in the file
String b = stripNonNumeric(stringvaluefromfile);
int a = Integer.parseInt(b);
public static String stripNonNumeric(String number) {
//System.out.println(number);
if (number == null || number.isEmpty()) {
return "0";
}
Matcher matcher = numericPattern.matcher(number);
// strip out all non-numerics
StringBuffer sb = new StringBuffer("");
while (matcher.find()) {
sb.append(matcher.group());
}
// make sure there's only one dot
int prevDot = -1;
for (int i = sb.length() - 1; i >= 0; i--) {
if (sb.charAt(i) == '.') {
if (prevDot > 0) {
sb.deleteCharAt(prevDot);
}
prevDot = i;
}
}
if (sb.length() == 0) {
sb.append("0");
}
return sb.toString();
}`

Related

Reading a File without line breaks using Buffered reader

I am reading a file with comma separated values which when split into an array will have 10 values for each line . I expected the file to have line breaks so that
line = bReader.readLine()
will give me each line. But my file doesnt have a line break. Instead after the first set of values there are lots of spaces(465 to be precise) and then the next line begins.
So my above code of readLine() is reading the entire file in one go as there are no lined breaks. Please suggest how best to efficiently tackle this scenario.
One way is to replace String with 465 spaces in your text with new line character "\n" before iterating it for reading.
I second Ninan's answer: replace the 465 spaces with a newline, then run the function you were planning on running earlier.
For aesthetics and readability I would suggest using Regex's Pattern to replace the spaces instead of a long unreadable String.replace(" ").
Your code could like below, but replace 6 with 465:
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
String content = "DOG,CAT MOUSE,CHEESE";
Pattern p = Pattern.compile("[ ]{6}",
Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
String newString = p.matcher(content).replaceAll("\n");
System.out.println(newString);
}
My suggestion is read file f1.txt and write to anther file f2.txt by removing all empty lines and spaces then read f2.txt something like
FileReader fr = new FileReader("f1.txt");
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter("f2.txt");
String line;
while((line = br.readLine()) != null)
{
line = line.trim(); // remove leading and trailing whitespace
if (!line.equals("")) // don't write out blank lines
{
fw.write(line, 0, line.length());
}
}
Then try using your code.
You might create your own subclass of a FilterInputStream or a PushbackInputStream and pass that to an InputStreamReader. One overrides int read().
Such a class unfortunately needs a bit of typing. (A nice excercise so to say.)
private static final int NO_CHAR = -2;
private boolean fromCache;
private int cachedSpaces;
private int cachedNonSpaceChar = NO_CHAR;
int read() throws IOException {
if (fromCache) {
if (cachecSpaces > 0) ...
if (cachedNonSpaceChar != NO_CHAR) ...
...
}
int ch = super.read();
if (ch != -1) {
...
}
return ch;
}
The idea is to cache spaces till either a nonspace char, and in read() either take from the cache, return \n instead, call super.read() when not from cache, recursive read when space.
My understanding is that you have a flat CSV file without proper line break, which supposed to have 10 values on each line.
Updated:
1. (Recommended) You can use Scanner class with useDelimiter to parse csv effectively, assuming you are trying to store 10 values from a line:
public static void parseCsvWithScanner() throws IOException {
Scanner scanner = new Scanner(new File("test.csv"));
// set your delimiter for scanner, "," for csv
scanner.useDelimiter(",");
// storing 10 values as a "line"
int LINE_LIMIT = 10;
// implement your own data structure to store each value of CSV
int[] tempLineArray = new int[LINE_LIMIT];
int lineBreakCount = 0;
while(scanner.hasNext()) {
// trim start and end spaces if there is any
String temp = scanner.next().trim();
tempLineArray[lineBreakCount++] = Integer.parseInt(temp);
if (lineBreakCount == LINE_LIMIT) {
// replace your own logic for handling the full array
for(int i=0; i<tempLineArray.length; i++) {
System.out.print(tempLineArray[i]);
} // end replace
// resetting array and counter
tempLineArray = new int[LINE_LIMIT];
lineBreakCount = 0;
}
}
scanner.close();
}
Or use the BufferedReader.
You might not need the ArrayList to store all values if there is memory issue by replacing your own logic.
public static void parseCsv() throws IOException {
BufferedReader br = new BufferedReader(new FileReader(file));
// your delimiter
char TOKEN = ',';
// your requirement of storing 10 values for each "line"
int LINE_LIMIT = 10;
// tmp for storing from BufferedReader.read()
int tmp;
// a counter for line break
int lineBreakCount = 0;
// array for storing 10 values, assuming the values of CSV are integers
int[] tempArray = new int[LINE_LIMIT];
// storing tempArray of each line to ArrayList
ArrayList<int[]> lineList = new ArrayList<>();
StringBuilder sb = new StringBuilder();
while((tmp = br.read()) != -1) {
if ((char)tmp == TOKEN) {
if (lineBreakCount == LINE_LIMIT) {
// your logic to handle the current "line" here.
lineList.add(tempArray);
// new "line"
tempArray = new int[LINE_LIMIT];
lineBreakCount = 0;
}
// storing current value from buffer with trim of spaces
tempArray[lineBreakCount] =
Integer.parseInt(sb.toString().trim());
lineBreakCount++;
// clear the buffer
sb.delete(0, sb.length());
}
else {
// add current char from BufferedReader if not delimiter
sb.append((char)tmp);
}
}
br.close();
}

Java using \034 as delimiter in a string

I am trying to use '\034' field separator character as a delimiter in a string.
The issue is when I hardcode "\034"+opField and write it to a file it works, but if the "\034" character is read from a file, it writes the output as string "col1\034col2'.
I tried using StringBuilder but it escapes the \034 to "\\034".
I am using the following code to read the character from the file:
try (BufferedReader br = new BufferedReader(new FileReader(fConfig))){
int lc = 1;
for(String line;(line = br.readLine())!=null;){
String[] rowList = line.split(delim);
int row_len = rowList.length;
if (row_len<2){
System.out.println("Incorrect dictionary file row:"+fConfig.getAbsolutePath()+"\nNot enough values found at row:"+line);
}else{
String key = rowList[0];
String value = rowList[1];
dictKV.put(key, value);
}
lc++;
}
}catch(Exception e){
throw e;
}
Any help is welcome...
[update]: The same thing is happening with '\t' character, if harcoded fine, but if read from a file its getting appended as characters. "col0\tcol1"
if(colAl.toLowerCase().contains(" as ")){
String temp = colAl.replaceAll("[ ]+as[ ]+"," | ");
ArrayList<String> tempA = this.brittle_delim(temp,'|');
colAl = tempA.get(tempA.size()-1);
colAl = colAl.trim();
}else {
ArrayList<String> tempA = this.brittle_delim(colAl,' ');
colAl = tempA.get(tempA.size()-1);
colAl = colAl.trim();
}
if(i==0){
sb.append(colAl);
headerCols+=colAl.trim();
}else{
headerCols+= this.output_field_delim + colAl;
sb.append(this.output_field_delim);
sb.append(colAl);
}
}
}
System.out.println("SB Header Cols:"+sb.toString());
System.out.println("Header Cols:"+headerCols);
Output:
SB Header Cols:
SPRN_CO_ID\034FISC_YR_MTH_DSPLY_CD\034CST_OBJ_CD\034PRFT_CTR_CD\034LEGL_CO_CD\034HEAD_CT_TYPE_ID\034FIN_OWN_CD\034FUNC_AREA_CD\034HEAD_CT_NR
Header Cols:
SPRN_CO_ID\034FISC_YR_MTH_DSPLY_CD\034CST_OBJ_CD\034PRFT_CTR_CD\034LEGL_CO_CD\034HEAD_CT_TYPE_ID\034FIN_OWN_CD\034FUNC_AREA_CD\034HEAD_CT_NR
In the above code if I do the following I am getting correct results:
headerCols+= "\034"+ colAl;
output:
SPRN_CO_IDFISC_YR_MTH_DSPLY_CDCST_OBJ_CDPRFT_CTR_CDLEGL_CO_CDHEAD_CT_TYPE_IDFIN_OWN_CDFUNC_AREA_CDHEAD_CT_NR
The FS characters are there even if they are geting removed here
You should provide an example demonstrating your problem. Not just incomplete code snippets.
Following runable snippet does what you explained.
// create a file one line
byte[] bytes = "foo bar".getBytes(StandardCharsets.ISO_8859_1);
String fileName = "/tmp/foobar";
Files.write(Paths.get(fileName), bytes);
String headerCols = "";
String outputFieldDelim = "\034";
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
// read the line from the file and split by blank character
String[] cols = br.readLine().split(" ");
// contcatenate the values with "\034"
// but ... for your code ...
// don't concatenate String objects in a loop like below
// use a StringBuilder or StringJoiner instead
headerCols += outputFieldDelim + cols[0];
headerCols += outputFieldDelim + cols[1];
}
// output with the "\034" character
System.out.println(headerCols);
I guess this is where I found my solution and the actual words for my Question.
How to unescape string literals in java

comparison of each line in two file

I have a task to compare lines in two files.. values stores in files as string. I am new to Java so please forgive if there is some silly mistake :)
file1 contains
1044510=>40000
2478436011=>10000
2478442011=>3500
2498736011=>3000
2498737011=>550
2478443011=>330
2478444011=>1,550
File two contains
1044510=>30,097
2478436011=>9,155
2478442011=>2,930
2498736011=>2,472
2498737011=>548
2478443011=>313
2478444011=>1,550
I want to take line one from first file and second file and check if value of line1 from first file is greater than second file or not. (40000>30,097) or not. Dont want to take values before "=>".
I have done a sample code but i am getting error while running.
private static void readfiles() throws IOException {
BufferedReader bfFirst = new BufferedReader(new FileReader(first_list));
BufferedReader bfSecond = new BufferedReader(new FileReader(second_list));
int index = 0;
while (true) {
String partOne = bfFirst.readLine();
String partTwo = bfSecond.readLine();
String firstValue=null;
String secondValue=null;
int firstValueInt;
int secondValueInt;
if (partOne == null || partTwo == null)
{
break;
}
else
{
System.out.println(partOne + "-----\t-----" + partTwo);
firstValue=partOne.split("=>")[1];
secondValue=partTwo.split("=>")[1];
System.out.println("first valueee"+firstValue);
System.out.println("second value"+secondValue);
firstValueInt=Integer.parseInt(firstValue);
secondValueInt=Integer.parseInt(secondValue);
if(secondValueInt>firstValueInt)
{
System.out.println("greater");
}
else
{
System.out.println("lesser");
}
}
}
}
}
This is the exception i get
Exception in thread "main" java.lang.NumberFormatException: For input string: "30,097"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at com.bq.pricefinder.flipkart.findProductDifferenceFromFiles.readfiles(findProductDifferenceFromFiles.java:45)
at com.bq.pricefinder.flipkart.findProductDifferenceFromFiles.main(findProductDifferenceFromFiles.java:18)
The problem here is that you are parsing decimal value as integer.
The exception
java.lang.NumberFormatException: For input string: "30,097"
is clear which says that decimal value 30,097 in an invalid format for an integer.
Use float instead of int, and then compare. Also, sometimes it depends on the locale what decimal symbol is used, it can be , for one country and . for another. Read also THIS.
Integer.parseInt can't work on strings containing non-digits. That's the cause of the NumberFormatException. Use it like this :
firstValueInt=Integer.parseInt(firstValue.replaceAll(",",""));
secondValueInt=Integer.parseInt(secondValue.replaceAll(",",""));
you can get integer only by adding this lines
firstValue = firstValue.replaceAll("[^0-9]", "");
secondValue = secondValue.replaceAll("[^0-9]", "");
then convert it to integer

How to read multiple lines using FileReader only?

I have the following code:
public class Reader {
public static void main(String[] args) throws IOException {
try (FileReader in = new FileReader("D:/test.txt")) {
// BufferedReader br = new BufferedReader(in);
int line = in .read();
for (int i = 0; i < line; i++) {
//System.out.println(line);
System.out.println((char) line);
line = in .read();
}
}
}
}
and a file Test.txt with the content:
Hello
Java
When I run above code it only reads Hello. I would like to read multiple lines using FileReader only. I don't want to use BufferedReader or InputStreamReader etc. Is that possible?
I don't think this version of the code prints "Hello".
You are calling:
int line = in.read();
What does this do? Look in the Javadocs for Reader:
public int read()
throws IOException
Reads a single character. This method will block until a character is available, an I/O error occurs, or the end
of the stream is reached.
(emphasis mine)
Your code reads the 'H' from 'Hello', which is 72 in ASCII.
Then it goes into your loop, with line==72, so it goes into the loop:
for(int i=0;i<line;i++)
... making the decision "is 0 less than 72? Yes, so I'll go into the loop block".
Then each time it reads a character the value of line changes to another integer, and each time loop goes around i increments. So the loop says "Keep going for as long as the ASCII value of the character is greater than the number of iterations I've counted".
... and each time it goes around, it prints that character on a line of its own.
As it happens, for your input, it reads end-of-file (-1), and as -1 < i, the loop continue condition is not met.
But for longer inputs it stop on the first 'a' after the 97th character, or the first 'b' after the 98th character, and so on (because ASCII 'a' is 97, etc.)
H
e
l
l
o
J
a
v
a
This isn't what you want:
You don't want your loop to repeat until i >= "the character I just read". You want it to repeat until in.read() returns -1. You have probably been taught how to loop until a condition is met.
You don't want to println() each character, since that adds newlines you don't want. Use print().
You should also look at the Reader.read(byte[] buffer) method, and see if you can write the code to work in bigger chunks.
Two patterns you'll use over and over again in your programming career are:
Type x = getSomehow();
while(someCondition(x)) {
doSomethingWith(x);
x = getSomehow();
}
... and ...
Type x = value_of_x_which_meets_condition;
while(someCondition(x)) {
x = getSomehow();
doSomethingWith(x);
}
See if you can construct something with FileReader and the value you get from it, filling in the "somehows".
Reading file character by character without any buffering stream is extremely ineffective. I would probably wrap FileReader in some BufferedReader or simply used Scanner to read condent of file, but if you absolutely want/need/have to use only FileReader then you can try with
int line = in.read();
while (line != -1) {
System.out.print((char) line);
line = in.read();
}
instead of your for (int i = 0; i < line; i++) {...} loop.
Read carefully slims answer. In short: reading condition shouldn't care if number of characters you read is less then numeric representation of currently read character (i < line). Like in case of
My name
is
not important now
This file has few characters which you normally will not see like \r and \n and in reality it looks like
My name\r\n
\r\n
is\r\n
\r\n
not important now
where numeric representation of \r is 10, so after you read My name\r\n (which is 9 characters because \r and \n are single character representing line separator) your i will become 10 and since next character you will try to read is \r which is also represented by 10 your condition i<line will fail (10<10 is not true).
So instead of checking i<line you should check if read value is not EoF (End of File, or End of Stream in out case) which is represented by -1 as specified in read method documentation so your condition should look like line != -1. And because you don't need i just use while loop here.
Returns:
The character read, or -1 if the end of the stream has been reached
You will have to read the content char by char and parse for a new line sequence.
A new line sequence can be any of the following:
a single cariage return '\r'
a single line feed '\n'
a carriage return followed by a line feed "\r\n"
EDIT
You could try the following:
public List<String> readLinesUsingFileReader(String filename) throws IOException {
List<String> lines = null;
try (FileReader fileReader = new FileReader(filename)) {
lines = readLines(fileReader);
}
return lines;
}
private List<String> readLines(FileReader fileReader) throws IOException {
List<String> lines = new ArrayList<>();
boolean newLine = false;
int c, p = 0;
StringBuilder line = new StringBuilder();
while(-1 != (c = fileReader.read())) {
if(c == '\n' && p != '\r') {
newLine = true;
} else if(c == '\r') {
newLine = true;
} else {
if(c != '\n' && c != '\r') {
line.append((char) c);
}
}
if(newLine) {
lines.add(line.toString());
line = new StringBuilder();
newLine = false;
}
p = c;
}
if(line.length() > 0) {
lines.add(line.toString());
}
return lines;
}
Note that the code above reads the whole file into a List, this might not be well suited for large files! You may want in such a case to implement an approach which uses streaming, i.e. read one line at a time, for example String readNextLine(FileReader fileReader) { ... }.
Some basic tests:
Create test files to read
private final static String txt0 = "testnl0.txt";
private final static String txt1 = "testnl1.txt";
private final static String txt2 = "testnl2.txt";
#BeforeClass
public static void genTestFile() throws IOException {
try (OutputStream os = new FileOutputStream(txt0)) {
os0.write((
"Hello\n" +
",\r\n" +
"World!" +
"").getBytes());
}
try (OutputStream os = new FileOutputStream(txt1)) {
os.write((
"\n" +
"\r\r" +
"\r\n" +
"").getBytes());
}
try (OutputStream os = new FileOutputStream(txt2)) {
os.write((
"").getBytes());
}
}
Test using the created files
#Test
public void readLinesUsingFileReader0() throws IOException {
List<String> lines = readLinesUsingFileReader(txt0);
Assert.assertEquals(3, lines.size());
Assert.assertEquals("Hello", lines.get(0));
Assert.assertEquals(",", lines.get(1));
Assert.assertEquals("World!", lines.get(2));
}
#Test
public void readLinesUsingFileReader1() throws IOException {
List<String> lines = readLinesUsingFileReader(txt1);
Assert.assertEquals(4, lines.size());
Assert.assertEquals("", lines.get(0));
Assert.assertEquals("", lines.get(1));
Assert.assertEquals("", lines.get(2));
Assert.assertEquals("", lines.get(3));
}
#Test
public void readLinesUsingFileReader2() throws IOException {
List<String> lines = readLinesUsingFileReader(txt2);
Assert.assertTrue(lines.isEmpty());
}
If you have the new line character
public static void main(String[]args) throws IOException{
FileReader in = new FileReader("D:/test.txt");
char [] a = new char[50];
in.read(a); // reads the content to the array
for(char c : a)
System.out.print(c); //prints the characters one by one
in.close();
}
It will print
Hello
Java
I solved the above problem by using this code
public class Reader
{
public static void main(String[]args) throws IOException{
try (FileReader in = new FileReader("D:/test.txt")) {
int line = in.read();
while(line!=-1)
{
System.out.print((char)line);
line = in.read();
} }
}
}
But there is one more question if I write for loop instead of while like this
for(int i=0;i<line;i++)
It prints only first line.Could anybody tell me why?
Reader.read() returns int code of single char or -1 if end of the file is reached:
http://docs.oracle.com/javase/7/docs/api/java/io/Reader.html#read()
So, read the file char by char and check LF (Line feed, '\n', 0x0A, 10 in decimal), CR (Carriage return, '\r', 0x0D, 13 in decimal)and end-of-line codes.
Note: Windows OS uses 2 chars to encode the end of line: "\r\n". The most of others including Linux, MacOS, etc. use only "\n" to encode the end of line.
final StringBuilder line = new StringBuilder(); // line buffer
try (FileReader in = new FileReader("D:/test.txt")) {
int chAr, prevChar = 0x0A; // chAr - just read char, prevChar - previously read char
while (prevChar != -1) { // until the last read char is EOF
chAr = in.read(); // read int code of the next char
switch (chAr) {
case 0x0D: // CR - just
break; // skip
case -1: // EOF
if (prevChar == 0x0A) {
break; // no need a new line if EOF goes right after LF
// or no any chars were read before (prevChar isn't
// changed from its initial 0x0A)
}
case 0x0A: // or LF
System.out.println("line:" + line.toString()); // get string from the line buffer
line.setLength(0); // cleanup the line buffer
break;
default: // if any other char code is read
line.append((char) chAr); // append to the line buffer
}
prevChar = chAr; // remember the current char as previous one for the next iteration
}
}

Trying to parse a string to int from a file. Get NumberFormatException: For input string: "", eaven tho string appears to be an good int string. Java

I have been trying to figure this out for couple of hours now and I hope one of you can help me. I have an file (actually two but thats not important) that have some rows and columns with numbers and blank spaces between. And I'm trying to read those with BufferedReader. And that works great. I can print out the strings & chars however I want. But when I try to parse those strings and chars I get the following error:
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at FileProcess.processed(FileProcess.java:30)
at DecisionTree.main(DecisionTree.java:16)
From what I have found with google I think the error is located in how I read my file.
public class ReadFiles {
private BufferedReader read;
public ReadFiles(BufferedReader startRead) {
read = startRead;
}
public String readFiles() throws IOException {
try {
String readLine = read.readLine().trim();
String readStuff = "";
while(readLine != null) {
readStuff += (readLine + "\n");
readLine = read.readLine();
}
return readStuff;
}
catch(NumberFormatException e) {
return null;
}
}
And for the parsing bit
public class FileProcess {
public String processed() throws IOException {
fileSelect fs = new fileSelect();
ReadFiles tr = new ReadFiles(fs.traning());
String training = tr.readFiles();
ReadFiles ts = new ReadFiles(fs.test());
String test = ts.readFiles();
List liste = new List(14,test.length());
String[] test2 = test.split("\n");
for(int i = 0; i<test2[0].length(); i++) {
char tmp = test.charAt(i);
String S = Character.toString(tmp).trim();
//int i1 = Integer.parseInt(S);
System.out.print(S);
}
This isn't the actual code for what I planning to do with the output, but the error appears at the code that is commented out. So my string output is as following:
12112211
Which seems good to parse to integer. But it does not work. I tried to manually see what's in the char position 0 and 1, for 0 I get 1, but for 1 I get nothing aka "". So how can I remove the ""? I hope you guys can help me out, and let me know if you need more info. But I think I have covered what's needed.
Thanks in advance :)
Yeah, and another thing: If I replace "" with "0" it works, but then I get all those zeros which I can't find a clever way to remove. But is it possible to maybe skip them while parsing or something? My files only hold 1 and 2, so it wouldn't interfere with anything if it is possible.
The string "" will be returned if you have 2 of the splitting characters next to each other (i.e. \n\n) or if there is a whitespace character being passed into the trim() call so ignore empty strings and carry on.
You could use the Scanner class to parse for ints, skipping Whitespace:
sc = new java.util.Scanner (line);
sc.nextInt ();
Another idea is to trim the line, split, and parse the parts:
lin = line.trim ();
String [] words = lin.split (" +");
for (String si : words)
Integer.parseInt (si);

Categories