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

Suppose a right triangle is placed in a plane as shown below. The right-angle po

ID: 3841861 • Letter: S

Question

Suppose a right triangle is placed in a plane as shown below. The right-angle point (B) is placed at (0, 0), and the other two points (C and A) are placed at (200, 0) and (0, 100). Write a program that prompts the user to enter a point with x- and y-coordinates and determines whether the point is inside the triangle.

Here are the sample runs:

Enter a point's x- and y-coordinates: 100.5 25.5
The point is in the triangle

and

Enter a point's x- and y-coordinates: 100.5 50.5
The point is not in the triangle

Explanation / Answer


import java.io.*;
import java.util.*;
import java.util.Scanner;
class triangle
{
public static void main (String args[])
{
double x, y, intx, inty;
Scanner scan = new Scanner(System.in);
System.out.println(" Enter a point's x and y - co-ordinates:");
x = scan.nextDouble();
y = scan.nextDouble();
intx = (-x * (200 * 100))/(-y * 200 -x * 100);
inty = (-y * (200 * 100))/(-y * 200 -x * 100);
if(x < intx || y < inty)
{
System.out.println(" The point is in the Triangle");
}
else
{
System.out.println(" The point is not in the Triangle");
}
}
}


OUTPUT


Enter a point's x and y - co-ordinates:100.5 25.5
The point is in the Triangle


Enter a point's x and y - co-ordinates:100.5 50.5
The point is not in the Triangle

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote