-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineComparisonProblemUC1.java
More file actions
49 lines (36 loc) · 1.55 KB
/
LineComparisonProblemUC1.java
File metadata and controls
49 lines (36 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.linecompare;
import java.util.Scanner;
public class LineComparisonProblemUC1 {
public static void main(String[] args) {
//also can use try to test the selected code during execution
Scanner sc = new Scanner(System.in);
double x1,x2,y1,y2,x3,y3,x4,y4;
int line1,line2;
//For first line
System.out.println("Enter x1 & y1 values of First point");
x1 = sc.nextDouble();
y1 = sc.nextDouble();
System.out.println("Enter x2 & y2 values of Second point");
x2 = sc.nextDouble();
y2 = sc.nextDouble();
line1=(int)Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
System.out.println("Distance of the First line = "+line1);
//For second line
System.out.println("Enter x3 & y3 values of Third point");
x3 = sc.nextDouble();
y3 = sc.nextDouble();
System.out.println("Enter x4 & y4 values of Fourth point");
x4 = sc.nextDouble();
y4 = sc.nextDouble();
line2 = (int)Math.sqrt((x4 - x3) * (x4 - x3) + (y4 - y3) * (y4 - y3));
System.out.println("Distance of Second line = "+line2);
String str1 = Double.toString(line1);
String str2 = Double.toString(line2);
//Comparing the two lines using the "compareTo" method
int check = str1.compareTo(str2);
if(check == 0)
System.out.println("Both the lines are Equal");
else
System.out.println("Both the lines are Not equal");
}
}