Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.*;
- class Task5
- {
- /*public void Vectors(double vectorLength1, double vectorLength2)
- {
- int x1, x2, y1, y2;
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter x for vector 1 = " );
- do{
- x1 = sc.nextInt();
- }while (Character.isDigit(x1));
- System.out.println("Enter y for vector 1 = " );
- do{
- y1 = sc.nextInt();
- }while (Character.isDigit(y1));
- System.out.println("Enter x for vector 2 = ");
- do{
- x2 = sc.nextInt();
- }while (Character.isDigit(x2));
- System.out.println("Enter y for vector 2 = " );
- do{
- y2 = sc.nextInt();
- }while (Character.isDigit(y2));
- System.out.println("" + x1 + "" + y1 + "" + x2 + "" + y2);
- vectorLength1 = Math.sqrt(Math.pow(x1,2)+Math.pow(y1,2));
- vectorLength2 = Math.sqrt(Math.pow(x2,2)+Math.pow(y2,2));
- if(vectorLength1 == vectorLength2)
- {
- double sum = vectorLength1 + vectorLength2;
- System.out.println("Sum of the vectors is equal to " + sum);
- }else System.out.println("Vectors are not equal !!! Please try again enter the vectors");
- }*/
- public static void main(String[] args)
- {
- char x1, x2, y1, y2;
- double vectorLength1;
- double vectorLength2;
- Scanner sc = new Scanner(System.in);
- do{
- System.out.println("Enter x for vector 1 = " );
- x1 = sc.next().charAt(0);
- }while(!Character.isDigit(x1));
- do{
- System.out.println("Enter y for vector 1 = " );
- y1 = sc.next().charAt(0);
- }while (!Character.isDigit(y1));
- do{
- System.out.println("Enter x for vector 2 = ");
- x2 = sc.next().charAt(0);
- }while (!Character.isDigit(x2));
- do{
- System.out.println("Enter y for vector 2 = " );
- y2 = sc.next().charAt(0);
- }while (!Character.isDigit(y2));
- System.out.println("" + x1 + "" + y1 + "" + x2 + "" + y2);
- vectorLength1 = Math.sqrt(Math.pow(x1,2)+Math.pow(y1,2));
- vectorLength2 = Math.sqrt(Math.pow(x2,2)+Math.pow(y2,2));
- if(vectorLength1 == vectorLength2)
- {
- double sum = vectorLength1 + vectorLength2;
- System.out.println("Sum of the vectors is equal to " + sum);
- }else System.out.println("Vectors are not equal !!! Please try again enter the vectors");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement