-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab 12 lexicographically.txt
51 lines (34 loc) · 1.66 KB
/
Lab 12 lexicographically.txt
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
50
51
package Lab12;
public class Lecture12 {
public static void main (String [] args)
{
//1. Write a Java program to compare two strings lexicographically.
// Two strings are lexicographically equal if they are the same
// length and contain the same characters in the same positions.
String s1 = "The content 2 ";
String s2 = "The content 1 ";
System.out.println("String 1: " + s1);
System.out.println("String 2: " + s2);
// Compare these two strings.
int result = s1.compareTo(s2);
// the results of the comparison.
if (result < 0)
{
System.out.println("" + s1 + " " +
" is less than " +
" " + s2 + " ");
}
else if (result == 0)
{
System.out.println(" " + s1 + " " +
" is equal to " +
"\"" + s2 + "\"");
}
else // if (result > 0)
{
System.out.println("\"" + s1 + "\"" +
" is greater than " +
"\"" + s2 + "\"");
}
}
}