Java:將100以內的數字翻譯成英文

bug不存在的發表於2021-10-08

package com.test;


import java.util.Scanner;


public class Day0308 {

    public static void main(String[] args) {

        String oneArr[] = { "zero", "one", "two", "three", "four", "five", "six",

                "seven", "eight", "nine" };

        String twoArr[] = {"ten", "eleven", "twelve", "thirteen", "fourteen",

                "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };

        String tenArr[] = {"twenty", "thirty", "fourty", "fifty", "sixty",

                "seventy", "eighty", "ninty" };

        Scanner scanner = new Scanner(System.in);

        System.out.println("請輸入數字");

        int m = scanner.nextInt();

        scanner.close();

        if (m < 10) {

            System.out.println(oneArr[m]);

        } else if (m < 20) {

            System.out.println(twoArr[m-10]);

        } else if (m < 100) {

            System.out.print(tenArr[m/10-2] + " ");

            if(m % 10 > 0) {

                System.out.println(oneArr[m%10]);

            }

        }

    }

}


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70007877/viewspace-2794961/,如需轉載,請註明出處,否則將追究法律責任。

相關文章