Write a program to take two strings as input then display the string which is longer. If both the strings are of same length then appropriate message will come using length().
Output:
Enter first String
Hello World
Enter second String
hello wOrLd
Both Strings are of same length
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.println("Enter first String");
String firstString = keyBoard.nextLine();
System.out.println("Enter second String");
String secondString = keyBoard.nextLine();
if (firstString.compareToIgnoreCase(secondString) == 0) {
System.out.println("Both Strings are of same length");
} else {
System.out.println("Both Strings are NOT of same length");
}
keyBoard.close();
}
}
Comments
Leave a comment