Answer to Question #245353 in Java | JSP | JSF for Selma

Question #245353
Create a program that takes in two words, check for equality ignoring the cases, if the words are
equal the print the word in upper case with an appropriate message however if the words are
different then print the two words in lower case with an appropriate message.
Sample run 1:
Enter two words separated by spaces: Welcome WELCOME
Output: You have only entered one word: “WELCOME”
Sample run 2:
Enter two words separated by spaces: NUST Students
Output: You have entered two words: “nust” and “students”
1
Expert's answer
2021-10-01T13:27:54-0400
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
		System.out.print("Enter two words separated by spaces: ");
		String word1 = keyboard.next();
		String word2 = keyboard.next();


		if (word1.compareToIgnoreCase(word2)==0) {
			System.out.println("You have only entered one word: \"" + word1.toUpperCase() + "\"");
		} else {
			System.out.println(
					"You have entered two words: \"" + word1.toLowerCase() + "\" and \"" + word2.toLowerCase() + "\"");
		}
		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