-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringEqualityDemo.java
More file actions
37 lines (30 loc) · 1007 Bytes
/
Copy pathStringEqualityDemo.java
File metadata and controls
37 lines (30 loc) · 1007 Bytes
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
/**
* StringEqualityDemo.java
* Demos the use of String's equals method in an if structure
*/
import java.util.*;
public class StringEqualityDemo
{
public static void main(String[] args)
{
String s1, s2;
System.out.println("Enter two lines of text:");
Scanner keyboard = new Scanner(System.in);
s1 = keyboard.nextLine( );
s2 = keyboard.nextLine( );
if (s1.equals(s2))
System.out.println("The two lines are equal.");
else
System.out.println("The two lines are not equal.");
if (s2.equals(s1))
System.out.println("The two lines are equal.");
else
System.out.println("The two lines are not equal.");
if (s1.equalsIgnoreCase(s2))
System.out.println(
"But the lines are equal, ignoring case.");
else
System.out.println(
"Lines are not equal, even ignoring case.");
}
}