优质解答
放到一个数组最简单了,根据数字去索引.
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