SHARE
TWEET

TASK5 JAVA AA

Mary_99 Mar 28th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.*;
  3.  
  4. class Task5
  5. {
  6.  
  7.   /*public void Vectors(double vectorLength1, double vectorLength2)
  8.   {
  9.         int x1, x2, y1, y2;
  10.  
  11.         Scanner sc = new Scanner(System.in);
  12.  
  13.         System.out.println("Enter x for vector 1 = " );
  14.  
  15.         do{
  16.         x1 = sc.nextInt();
  17.         }while (Character.isDigit(x1));
  18.  
  19.         System.out.println("Enter y for vector 1 = " );
  20.  
  21.         do{
  22.         y1 = sc.nextInt();
  23.         }while (Character.isDigit(y1));
  24.  
  25.         System.out.println("Enter x for vector 2 = ");
  26.  
  27.         do{
  28.         x2 = sc.nextInt();
  29.       }while (Character.isDigit(x2));
  30.  
  31.         System.out.println("Enter y for vector 2 = " );
  32.  
  33.         do{
  34.         y2 = sc.nextInt();
  35.         }while (Character.isDigit(y2));
  36.  
  37.  
  38.         System.out.println("" + x1 + "" + y1 + "" + x2 + "" + y2);
  39.  
  40.         vectorLength1 = Math.sqrt(Math.pow(x1,2)+Math.pow(y1,2));
  41.         vectorLength2 = Math.sqrt(Math.pow(x2,2)+Math.pow(y2,2));
  42.  
  43.         if(vectorLength1 == vectorLength2)
  44.         {
  45.           double sum = vectorLength1 + vectorLength2;
  46.           System.out.println("Sum of the vectors is equal to " + sum);
  47.  
  48.         }else System.out.println("Vectors are not equal !!! Please try again enter the vectors");
  49.  
  50.   }*/
  51.  
  52.  
  53.   public static void main(String[] args)
  54.  
  55.     {
  56.  
  57.       char x1, x2, y1, y2;
  58.       double vectorLength1;
  59.      double vectorLength2;
  60.  
  61.       Scanner sc = new Scanner(System.in);
  62.  
  63.       do{
  64.         System.out.println("Enter x for vector 1 = " );
  65.         x1 = sc.next().charAt(0);
  66.       }while(!Character.isDigit(x1));
  67.  
  68.       do{
  69.         System.out.println("Enter y for vector 1 = " );
  70.         y1 = sc.next().charAt(0);
  71.       }while (!Character.isDigit(y1));
  72.  
  73.       do{
  74.         System.out.println("Enter x for vector 2 = ");
  75.         x2 = sc.next().charAt(0);
  76.       }while (!Character.isDigit(x2));
  77.  
  78.       do{
  79.         System.out.println("Enter y for vector 2 = " );
  80.         y2 = sc.next().charAt(0);
  81.       }while (!Character.isDigit(y2));
  82.  
  83.  
  84.       System.out.println("" + x1 + "" + y1 + "" + x2 + "" + y2);
  85.  
  86.       vectorLength1 = Math.sqrt(Math.pow(x1,2)+Math.pow(y1,2));
  87.       vectorLength2 = Math.sqrt(Math.pow(x2,2)+Math.pow(y2,2));
  88.  
  89.       if(vectorLength1 == vectorLength2)
  90.       {
  91.         double sum = vectorLength1 + vectorLength2;
  92.         System.out.println("Sum of the vectors is equal to " + sum);
  93.  
  94.       }else System.out.println("Vectors are not equal !!! Please try again enter the vectors");
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.       }
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top