Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class ToOrdinal {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- toOrdinal to = new toOrdinal();
- System.out.print("0以上の整数を入力:");
- String x = sc.nextLine();
- if(Integer.parseInt(x) < 0) {
- System.out.println("0以上を入力してくだい");
- System.exit(0);
- }
- System.out.println(to.check(x));
- }
- }
- class toOrdinal {
- public String check(String x) {
- String n = x.substring(x.length() - 1);
- switch (n) {
- case "1":
- return x + "st";
- case "2":
- return x + "nd";
- case "3":
- return x + "rd";
- default:
- return x + "th";
- }
- }
- }
Add Comment
Please, Sign In to add comment