java中的二维数组

来源:互联网 发布:互联网大数据论文题目 编辑:程序博客网 时间:2024/05/18 01:14



package java1;


//导包
import java.util.*;


class mygame
{
public static void main(String[] args)
{
// 导用方法
shop();


}


public static void shop()
{
String[] shopNames = new String[100];// 创建安置商品的数组
int[] shopNums = new int[100];// 创建商品的编号


// 给对应商品进行编号
shopNames[0] = "苹果";
shopNames[1] = "梨";
shopNames[2] = "草莓";
shopNames[3] = "饼干";
shopNames[4] = "可乐";
shopNames[5] = "酒";


while (true)
{
// 键盘输入数字
Scanner ac = new Scanner(System.in);
int sc = ac.nextInt();


// 利用for循环查找数字对应的商品
for (int i = 0; i < shopNames.length; i++)
{
int shopNum = shopNums[i];


}
// 打印输出
System.out.println(shopNames[sc]);
}


}
}

原创粉丝点击