qq小妹头
//英文指的是英文单词吧,比如1输出one,2输出two,这貌似只能创建一个数字数组//我写了0到10的,0到999类似import java.util.Scanner;public class Convert { static final String WORDS_LIST[]={ "zero","one","two","three","four","five","six","seven","eight","nine","ten"}; public static void main(String []args) { Scanner scanner = new Scanner(System.in); int number; while(scanner.hasNextInt()){ number = scanner.nextInt(); if(number == -1){ System.out.println("exit"); scanner.close(); break; } if(number > WORDS_LIST.length){ System.out.println("Out of range error!"); continue; } String msg = String.format("The word of %1$s is:", number) + WORDS_LIST[number]; System.out.println(msg); } }}
一首ciao情歌
为什么要用switch啊?如果你的意思是你的数字和英文是在asc码表中是对应的话根本不需要switch啊,系统直接会输出数字对应的英文啊。难道你的意思是你的每个英文是有编号的,输入编号后输出英文?这倒是要用switch 不过这个很简单啊比如scanf("%d",&a);switch(a){case 1:printf("first");break;case 2:printf("second");break;case 3:printf("third");break;default:printf("wrong");break;}一般形式就是这样的
优质英语培训问答知识库