Answer to Question #291576 in Java | JSP | JSF for Edward

Question #291576

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


1
Expert's answer
2022-01-28T12:52:49-0500


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();
	}
}

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
New on Blog
APPROVED BY CLIENTS