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

2019-06-18

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
放到一个数组最简单了,根据数字去索引.
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
相关标签: 数字 英文单词
相关问答