Answer to Question #47371 in Java | JSP | JSF for neha reddy

Question #47371
Compare String values
Write a program that reads two strings from the keyboard and compares them and prints whether they are equal or not.
1
Expert's answer
2014-10-06T02:18:36-0400
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s1, s2;
System.out.print("Input first string: ");
s1 = in.next();
System.out.print("Input second string: ");
s2 = in.next();
if (s1.equals(s2)) {
System.out.println("The strings are equal");
} else {
System.out.println("The strings are not equal");
}
}
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS