Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EX2 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("x1 = ");
- int x1 = scan.nextInt();
- System.out.print("y1 = ");
- int y1 = scan.nextInt();
- System.out.print("x2 = ");
- int x2 = scan.nextInt();
- System.out.print("y2 = ");
- int y2 = scan.nextInt();
- double distance = distance(x1, y1, x2, y2);
- System.out.println("(" + x1 + ", " + y1 + ") to (" + x2 + ", " + y2 + ") => " + distance);
- }
- public static double distance(int x1, int y1, int x2, int y2) {
- return (double) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement