0
import java.io.*;
import java.util.*;

public class array {
    public static void main(String[] args) throws IOException {
        FileInputStream in = null;
        FileOutputStream out = null;
       
try {
    in = new FileInputStream("input.txt");
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String line = null;
    while ((line = reader.readLine()) != null) {
       String split[]=line.split(",");
      
    }


}
   
 catch (IOException x) {
    System.err.println(x);
} finally {
    if (in != null) in.close();
}}}

I'm stuck at how to convert string in split into int. My input.txt :

a,b,c
2,2,1
1,1,1
2,2,1
3,3,1
4,4,1
5,5,1
1,6,2
2,7,2
3,8,2
4,9,2
5,10,2

Anyone can help?

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by BestJewSinceJC
0

Use string.split(","); then use a for loop to iterate over the array it returns. Use the Integer.parseInt(string) method to convert each String in the array into an int.

0

Use string.split(","); then use a for loop to iterate over the array it returns. Use the Integer.parseInt(string) method to convert each String in the array into an int.

can you show me the code? please...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.