作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/16 18:08:56
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