-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString9.java
More file actions
45 lines (35 loc) · 1.27 KB
/
String9.java
File metadata and controls
45 lines (35 loc) · 1.27 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
import java.util.*;
public class String9 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("Version Comparison:");
for (int i = 1; i <= n; i++) {
String v1 = sc.next();
String v2 = sc.next();
String[] a = v1.split("\\.");
String[] b = v2.split("\\.");
int max = Math.max(a.length, b.length);
int result = 0;
for (int j = 0; j < max; j++) {
int num1 = j < a.length ? Integer.parseInt(a[j]) : 0;
int num2 = j < b.length ? Integer.parseInt(b[j]) : 0;
if (num1 > num2) {
result = 1;
break;
} else if (num1 < num2) {
result = -1;
break;
}
}
if (result == 1) {
System.out.println(i + ". " + v1 + " vs " + v2 + " -> v1 is Newer");
} else if (result == -1) {
System.out.println(i + ". " + v1 + " vs " + v2 + " -> v2 is Newer");
} else {
System.out.println(i + ". " + v1 + " vs " + v2 + " -> Equal");
}
}
sc.close();
}
}