Use Booleans, STRINGS, use string classes, create method to take input arguments
ID: 3660779 • Letter: U
Question
Use Booleans, STRINGS, use string classes, create method to take input arguments, create a method to return a value, write java statements to pass objects to methods (1) Write a method that will compare the value of two Strings. The method should return a value that you can use in a main method. (2) Write a main method that will use your string comparison. a. Request two words to be entered from the keyboard. b. If they are the same return the values of both words andExplanation / Answer
import java.util.Scanner; class Compare_Strings { public static void main(String args[]) { String s1, s2; Scanner in = new Scanner(System.in); System.out.println("Enter the first string"); s1 = in.nextLine(); System.out.println("Enter the second string"); s2 = in.nextLine(); if ( s1.compareTo(s2) > 0 ) System.out.println("First string is greater than second."); else if ( s1.compareTo(s2) < 0 ) System.out.println("First string is smaller than second."); else System.out.println("Both strings are equal."); } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.