----
import java.lang.Integer; import java.util.Scanner; import java.util.Random; class kuCun { //库存管理 public static void main(String[] args) { String[][] list={{"电视机","3"},{"洗衣粉","8"},{"食用盐","5"},{"口香糖","10"}}; show(list); } //执行封装 public static void show(String[][] list){ Scanner sc=new Scanner(System.in); while(true){ System.out.println("---------库存管理---------"); System.out.println("1.查看库存清单"); System.out.println("2.修改商品库存数量"); System.out.println("3.退出"); System.out.println("--------------------------"); System.out.println("请输入要执行的操作序号:"); int in=sc.nextInt(); switch(in){ case 1: look(list); break; case 2: select(list); break; case 3: return;//break aa;return:返回调用我的地方 default: System.out.println("--------------------------"); System.out.println("请输入正确的操作序号!"); System.out.println("--------------------------"); break; } } } //打印库存清单功能 public static void look(String[][] list){ int sum=0; for(int i=0;i<list.length;i++){ int num=Integer.parseInt(list[i][1]); sum+=num; for(int j=0;j<list[i].length;j++){ if(j==0){ System.out.print("商品名称:"+list[i][j]+" "); }else if(j==1){ System.out.print("库存数量:"+list[i][j]); } } System.out.println(); } System.out.println("总库存:"+sum); } //库存商品数量修改功能 public static void select(String[][] list){ System.out.println("请输入您要修改的商品序号"); for(int i=0;i<list.length;i++){ System.out.print((i+1)+":"+list[i][0]); System.out.println(); } Scanner sc=new Scanner(System.in); int in=sc.nextInt(); while(true){ switch(in){ case 1: System.out.println("商品名称为:"+list[in-1][0]); System.out.println("请修改库存数量"); String add=sc.next(); list[in-1][1]=add; System.out.println("修改后"+list[in-1][0]+"的库存为:"+add); System.out.println(); return; case 2: System.out.println("商品名称为:"+list[in-1][0]); System.out.println("请修改库存数量"); add=sc.next(); list[in-1][1]=add; System.out.println("修改后"+list[in-1][0]+"的库存为:"+add); System.out.println(); return; case 3: System.out.println("商品名称为:"+list[in-1][0]); System.out.println("请修改库存数量"); add=sc.next(); list[in-1][1]=add; System.out.println("修改后"+list[in-1][0]+"的库存为:"+add); System.out.println(); return; case 4: System.out.println("商品名称为:"+list[in-1][0]); System.out.println("请修改库存数量"); add=sc.next(); list[in-1][1]=add; System.out.println("修改后"+list[in-1][0]+"的库存为:"+add); System.out.println(); return; case 00: return; default: System.out.println("请输入正确的商品序号"); in=sc.nextInt(); break; } } } }
----
原文:https://www.cnblogs.com/l1314/p/12036248.html