In each line of the file provided, each line follows this structure:
8 numbers then 1 comma and then 2 numbers.
For example: 98468631,51
I would like to only use the two digits after the comma.
Here is the program:
import java.io.*;
import java.util.regex.*;
public class Read {
public static void main(String[] args) {
String[] marks = new String[100];
File file = new File("sd100-marks.csv");
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
for(int i = 0; i < 100; i++) {
try {
String line = reader.readLine();
String[] sp = line.split(",");
line = sp[0];
marks[i] = line;
} catch (IOException e) {
System.out.println("Could not read!");
}
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
for(int i = 0; i < 100; i++) {
System.out.println(marks[i]);
}
}
}
Basically, I am not sure what regular expression to use in the split()
method. For now, I have "," passed in to the method, but that is not useful for what I am trying to do and simply displays all of the numbers before the comma.