I am trying to add fractions from a file. I have managed to put each line into a string array.
example file:
3/2
4/3
5/6
array: 3/2, 4/3, 5/6
How can I split up these numbers so that a have a dimensional array that would be
3 ,2
4, 3
5,6
My code so far:
import java.util.Scanner; import java.io.FileNotFoundException; import java.lang.String; import java.io.File; import java.io.FileInputStream; public class Assignment1{ public static void main(String [] args){ //Reads file containing fractions Scanner inputFile = null; try { inputFile = new Scanner(new FileInputStream("fractions.txt")); } catch (FileNotFoundException e) { System.out.println("File not found or not opened."); System.exit(0); } String[]test = new String[100]; String[][]fractions = new String [100][2]; int count = 0; // //while(inputFile.hasNextLine()){ // count++; // inputFile.nextLine(); //} for(int i = 0; i<=31; i++){ test[i]=inputFile.nextLine(); } for(int i = 0; i<=31; i++){ fractions[i][i+1]= test } } }