Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CompareStrings {
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- System.out.print("Please enter first string: ");
- String Input1 = input.nextLine();
- System.out.print("Please enter second string: ");
- String Input2 = input.nextLine();
- int value = Input1.compareTo(Input2);
- System.out.println("Compare Results:");
- if (value == 0)
- System.out.println(Input1 + " == " + Input2);
- else if (value > 0)
- System.out.println(Input1 + " > " + Input2);
- else
- System.out.println(Input1 + " < " + Input2);
- }
- }
- /*run:
- Please enter first string: happy garden
- Please enter second string: happy garden
- Compare Results:
- happy garden == happy garden
- BUILD SUCCESSFUL (total time: 10 seconds)*/
- /*run:
- Please enter first string: happy
- Please enter second string: sad
- Compare Results:
- happy < sad
- BUILD SUCCESSFUL (total time: 6 seconds)
- */
- /*run:
- Please enter first string: tired
- Please enter second string: sleepy
- Compare Results:
- tired > sleepy
- BUILD SUCCESSFUL (total time: 18 seconds)*/
Advertisement
Add Comment
Please, Sign In to add comment