import java.util.ArrayList; // 引入 ArrayList 类
ArrayList<E> objectName =new ArrayList<>(); // 初始化
E: 泛型数据类型,用于设置 objectName 的数据类型,只能为引用数据类型。
objectName: 对象名。
int[] price = {15,20,29,18,32};
String[] food = {"番茄炒鸡蛋","鱼香肉丝","小炒黄牛肉","油淋茄子","清蒸噘鱼"};
for (int i = 0; i < 5; i++) {
System.out.println((i+1)+". "+food[i]+" "+price[i]);
}
ArrayList list = new ArrayList(5);
while (i <= 5) {
int number = sc.nextInt();
if (list.contains(number)) {
System.out.println("这个菜已经点过了");
continue;
}
else {
list.add(food[a-1]);
AllPrice = AllPrice+price[a-1];
System.out.println(f+list);
System.out.println("总价:"+AllPrice);
i++;
}
package 任务三;
import java.util.ArrayList;
import java.util.Scanner;
/** * @author ${范涛之} * @Description * @create 2021-11-15 20:49 */
public class Test {
public static void main(String[] args) {
int[] price = {15,20,29,18,32};
String[] food = {"番茄炒鸡蛋","鱼香肉丝","小炒黄牛肉","油淋茄子","清蒸噘鱼"};
for (int i = 0; i < 5; i++) {
System.out.println((i+1)+". "+food[i]+" "+price[i]);
}
System.out.println("请输入你想选的菜品编号:");
Scanner scanner = new Scanner(System.in);
int AllPrice = 0;
String f = "已选: ";
int i = 1;
ArrayList list = new ArrayList(5);
while (i<=5){
int a = scanner.nextInt();
if (list.contains(food[a-1])){
System.out.println("这个菜已经点过啦!");
continue;
}else {
list.add(food[a-1]);
AllPrice = AllPrice+price[a-1];
System.out.println(f+list);
System.out.println("总价:"+AllPrice);
i++;
}
}
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/justleavel/article/details/121344284
内容来源于网络,如有侵权,请联系作者删除!