Guest User

Untitled

a guest
Nov 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class ToOrdinal {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. toOrdinal to = new toOrdinal();
  7.  
  8. System.out.print("0以上の整数を入力:");
  9. String x = sc.nextLine();
  10.  
  11. if(Integer.parseInt(x) < 0) {
  12. System.out.println("0以上を入力してくだい");
  13. System.exit(0);
  14. }
  15.  
  16. System.out.println(to.check(x));
  17. }
  18. }
  19.  
  20. class toOrdinal {
  21. public String check(String x) {
  22. String n = x.substring(x.length() - 1);
  23. switch (n) {
  24. case "1":
  25. return x + "st";
  26.  
  27. case "2":
  28. return x + "nd";
  29.  
  30. case "3":
  31. return x + "rd";
  32.  
  33. default:
  34. return x + "th";
  35. }
  36. }
  37. }
Add Comment
Please, Sign In to add comment