Advertisement
Guest User

Ex2

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EX2 {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scan = new Scanner(System.in);
  8.  
  9. System.out.print("x1 = ");
  10. int x1 = scan.nextInt();
  11.  
  12. System.out.print("y1 = ");
  13. int y1 = scan.nextInt();
  14.  
  15. System.out.print("x2 = ");
  16. int x2 = scan.nextInt();
  17.  
  18. System.out.print("y2 = ");
  19. int y2 = scan.nextInt();
  20.  
  21. double distance = distance(x1, y1, x2, y2);
  22.  
  23. System.out.println("(" + x1 + ", " + y1 + ") to (" + x2 + ", " + y2 + ") => " + distance);
  24. }
  25.  
  26. public static double distance(int x1, int y1, int x2, int y2) {
  27.  
  28. return (double) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement