witchway915

Untitled

Dec 1st, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CompareStrings {
  4.  
  5. public static void main(String[] args){
  6.  
  7. Scanner input = new Scanner(System.in);
  8.  
  9. System.out.print("Please enter first string: ");
  10. String Input1 = input.nextLine();
  11.  
  12. System.out.print("Please enter second string: ");
  13. String Input2 = input.nextLine();
  14.  
  15. int value = Input1.compareTo(Input2);
  16.  
  17. System.out.println("Compare Results:");
  18. if (value == 0)
  19. System.out.println(Input1 + " == " + Input2);
  20. else if (value > 0)
  21. System.out.println(Input1 + " > " + Input2);
  22. else
  23. System.out.println(Input1 + " < " + Input2);
  24.  
  25.  
  26. }
  27. }
  28.  
  29. /*run:
  30. Please enter first string: happy garden
  31. Please enter second string: happy garden
  32. Compare Results:
  33. happy garden == happy garden
  34. BUILD SUCCESSFUL (total time: 10 seconds)*/
  35.  
  36. /*run:
  37. Please enter first string: happy
  38. Please enter second string: sad
  39. Compare Results:
  40. happy < sad
  41. BUILD SUCCESSFUL (total time: 6 seconds)
  42. */
  43.  
  44. /*run:
  45. Please enter first string: tired
  46. Please enter second string: sleepy
  47. Compare Results:
  48. tired > sleepy
  49. BUILD SUCCESSFUL (total time: 18 seconds)*/
Advertisement
Add Comment
Please, Sign In to add comment