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

import java.util.Scanner public class Distance { public static void main(String[

ID: 3884744 • Letter: I

Question

import java.util.Scanner public class Distance { public static void main(String[] args) System.out.println("Enter 4 real numbers for x1, y1, x2, y2"): double x1, x2, y1, y2: Scanner sc = new Scanner(System.in): x1 = Double.parseDouble(sc.next): y1 = Double.parseDouble(sc.next): x2 = Double.parseDouble(sc.next): y2 = Double.parseDouble(sc.next): double dist = Math. squareroot (Math.pow(x2 - x1, 2) + Math.pow(y2-y1, 2)): double m1, m2: m1 = (x1 + x2)/ 2.0: m2 = (y1 + y2)/2.0: System.out.println("Points: " ("+(Math.round(x1 * 10.0)/10.0) + +(Math.round(y1*10.0)/10)+) ("+(Math.round(x2 * 10.0)/10.0)+) + + (Math.round(y2 * 10.0/10.0)+)in"): System.out.println("Distance: " + (Math.round(dist * 10.0)/10.0)): System.out.println("Midpoint: " + (Math.round(dist * 10.0)/10.0): } }

Explanation / Answer

Answer

import java.util.Scanner;

public class HelloWorld

{

public static void main (String[] args)

{

System.out.println("Enter four real Numbers for x1,y1,x2,y2 : ");

double x1,x2,y1,y2;

Scanner sc=new Scanner(System.in);

x1=Double.parseDouble(sc.next());

y1=Double.parseDouble(sc.next());

x2=Double.parseDouble(sc.next());

y2=Double.parseDouble(sc.next());

double dist=Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));

double m1,m2;

m1=(x1+x2)/2.0;

m2=(y1+y2)/2.0;

System.out.println("Points: ("+(Math.round(x1*10.0)/10.0)+","+(Math.round(y1*10.0)/10.0)+")("+(Math.round(x2*10.0)/10.0)+","+(Math.round(y2*10.0)/10.0)+")");

System.out.println("Distance : "+(Math.round(dist*10.0)/10.0));

System.out.println("Midpoint : "+(Math.round(dist*10.0)/10.0));

}

}