JAVA如何把数字1-9转换成英文单词1-9

问题描述:

JAVA如何把数字1-9转换成英文单词1-9

放到一个数组最简单了,根据数字去索引.
import java.util.Scanner;
public class Du3 {
public static void main(String[] args) {
String[] numsAry = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

Scanner scanner = new Scanner(System.in);

System.out.print("Please input a number between 1 and 9: ");
int num = scanner.nextInt();

System.out.println(num + " to corresponding string is: " + numsAry[num]);
}
}
----------------
Please input a number between 1 and 9: 5
5 to corresponding string is: five