I am making a program that reads data from a formatted text document:
Planetary Data
Planet Diameter (km) Mass (kg) g (m/s^2)
- Mercury 4880 3.30E+23 3.70
- Venus 12104 4.87E+24 8.87
- Earth 12756 5.97E+24 9.79
- Mars 6794 6.24E+23 3.61
- Jupiter 142984 1.90E+27 24.80
- Saturn 120536 5.68E+26 10.43
- Uranus 51118 8.68E+25 8.86
- Neptune 49352 1.02E+26 11.17
In a text file it's a little more pretty but basically it is a four column document with info one number falling into each column. I am using the scanner class to try to read only the last column of numbers, but can't find an easy way to do it with out using a ton of nextLine() calls. Is there a better way to search just for those doubles, and pull them into an array with a scanner?
This code will compile but I get a mismatch error as soon as I run it.
public static double [] getGravity()throws IOException{
Scanner inFile = new Scanner(new File("PlanetaryData.txt"));
double [] getGrav = new double[8];
for(int i = 0; i < 8; i++){
getGrav[i] = inFile.nextDouble();
getGrav[i] /= 10;
System.out.println(getGrav[i]);
}
return getGrav;
}