Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a .txt file called geom.txt that looks like the following -3.0 2.0 # coor

ID: 3788025 • Letter: I

Question

I have a .txt file called geom.txt that looks like the following

-3.0 2.0                           # coordinates of P
2.0 -1.0                           # coordinates of Q
2.0 1.0 3.0                        # center and radius of C
-2.0 -3.0 5.0                      # center and radius of D
2.0 6.0 8.0 4.0                    # coord ul and lr of rectangle G
-3.0 2.0 4.0 -3.0                  # coord ul and lr of rectangle H

I am trying to find a code where I can get the floating numbers only and omit anything past the '#' sign

Explanation / Answer

Java Code :

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

public class ReadFile{

public static void main(String []args) throws IOException{
FileInputStream fin = new FileInputStream("geom.txt");
BufferedReader buffread = new BufferedReader(new InputStreamReader(fin));

String Line;

//Read File Line By Line
while ((Line = buffread.readLine()) != null) {
StringTokenizer st = new StringTokenizer(Line);
System.out.println (st.nextToken() + " " + st.nextToken());

// write your own code & use only st.nextToken() twice to get co-ordinates

}
buffread.close();
}
}

NOTE : At printing statement you can write your code as needed.