import java.util.Scanner;
/*数组查表法
* use the index of arrays to get the content of arrays.
* */
public class Arrays
{
public static void main(String[] args) {
//定义一个数组
String[] arr = {"","one","two","three","four","five","six","seven"};
//创建键盘录入对象
Scanner sc = new Scanner(System.in);
System.out.println("please set a index:");
int num = sc.nextInt();
if(num<1||num>=8) {
System.out.println("the index which you set is wrong");
} else {
System.out.println(arr[num]);
}
}
}
|
|