I am trying to find and print the number of occurrences of fractions from a file in my program. Fractions that simplify down to the same number counts as an occurrence, so 12/6 counts for 6/3 as well. So far, I have separated the fractions into numerator and denominator in separate arrays. The fractions I have in the numerator and denominator came from a separate array that I received from a file. I am having trouble trying to figure out how to simplify the fractions and also find the total occurrence of them. This is what I have so far:
String[] split = new String[2]; //String that holds numerator and denominator
int[] numerator = new int[100];
int[] denominator = new int[100];
for(int i = 0; i < numOfFractions; ++i) { //Loop through # of Lines
split = fractions[i].split("/"); //Split the fractions at the /
System.out.println("Test here " + fractions[i]); //TODO --> test
numerator[i] = Integer.parseInt(split[0]); //Numerator
System.out.println("Numerator = " + numerator[i]); //TODO --> test
denominator[i] = Integer.parseInt(split[1]); //Denominator
System.out.println("Denominator = " + denominator[i] + "\n"); //TODO --> test
}
}
These are the fractions obtained from a file. Each fraction is on its own line, and can assume every fraction will be (A/B) format
6/3
4/2
5/9
80/90
800/900
5/5
1/2
1/3
1/1
1/4
2/7
2/8
2/9