How do i do math problems with files in java?

Joined
Jan 8, 2022
Messages
11
Reaction score
0
here is the question: Read 3 coordinates of a triangle. Is it isosceles? Is it a right angle triangle? Which is the hypotenuse? i have to put the info into a file, and then use the info to solve a problem. how do i do this?
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
So, I've already answered the file reading part. Check out the static function Double.valueOf(String) for turning the text into a number. Once you have your three points, it's easily available math that you can Google. I'll help more here if needed, but, for example, for checking if it's a right triangle, you use the Pythagorean theorem on the sides and see if it's true. In this case, you'd first have to figure out your longest side for determining which side C, which is also a trivial equation.
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
Check out the thread on reading files for how to read a file line by line. Then, store each variable as you read it out. Assuming that they're all on different lines, back to back:
Code:
double a = in.readLine();
double b = in.readLine();
double c = in.readLine();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top