Advertisement
Guest User

Rangga compare

a guest
Nov 13th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class CompareStrings
  4. {
  5. public static void main(String args[])
  6. {
  7. String s1, s2;
  8. Scanner in = new Scanner(System.in);
  9.  
  10. System.out.println("Enter the first string");
  11. s1 = in.nextLine();
  12.  
  13. System.out.println("Enter the second string");
  14. s2 = in.nextLine();
  15.  
  16. if ( s1.compareTo(s2) > 0 )
  17. System.out.println("First string is greater than second.");
  18. else if ( s1.compareTo(s2) < 0 )
  19. System.out.println("First string is smaller than second.");
  20. else
  21. System.out.println("Both strings are equal.");
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement