Advertisement
cyphric

Analytic geometry

Oct 25th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package math;
  2. import java.math.*;
  3. import java.util.Scanner;
  4. import java.lang.*;
  5. @SuppressWarnings("unused")
  6. public class Math extends Globals {
  7.     public static void main(String[] args){
  8.         Math math = new Math();
  9.        
  10.         Scanner userInput = new Scanner(System.in);
  11.        
  12.         System.out.println("Var vänlig skriv in x1 och x2, följt av y1 och y2");
  13.         System.out.println("=================================================");
  14.        
  15.         System.out.print("X1:");
  16.         int x1 = userInput.nextInt();
  17.        
  18.         System.out.print("X2:");
  19.         int x2 = userInput.nextInt();
  20.        
  21.         System.out.print("Y1:");
  22.         int y1 = userInput.nextInt();
  23.        
  24.         System.out.print("Y2:");
  25.         int y2 = userInput.nextInt();
  26.        
  27.         if(x1 > x2 && y1 > y2)
  28.             z =  true;
  29.         else
  30.             z = false;
  31.        
  32.         double x3 = x1*x1;
  33.        
  34.         double x4 = x2*x2;
  35.        
  36.         double y3 = y1*y1;
  37.          
  38.         double y4 = y2*y2;
  39.        
  40.        
  41.         if(z == true){
  42.            
  43.             double d2;
  44.             d2 = (x3 - x4) + (y3 - y4);
  45.            
  46.             double d1;
  47.             d1 = Math.sqrt(d2);
  48.            
  49.             System.out.println("The distance is: " + d1);
  50.         }
  51.         else{
  52.             d2 = (x4 - x3) + (y4 - y3);
  53.            
  54.             d1 = Math.sqrt(d2);
  55.             System.out.println("The distance is: " + d1);
  56.         }
  57.        
  58.     }
  59.     private static double sqrt(double d2) {
  60.         // TODO Auto-generated method stub
  61.         return 0;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement