How to print an Array List on multiple lines?

后端 未结 3 882
慢半拍i
慢半拍i 2021-01-22 05:16

I\'m doing the MOOC java course, and I\'m stuck on exercise 76. Whenever I submit the answer it tells me to print each meal to a seperate line. How would I go about doing this?<

3条回答
  •  没有蜡笔的小新
    2021-01-22 05:28

     import java.util.ArrayList;
    
    public class Menu {
    
       private ArrayList meals;
    
    public Menu() {
        this.meals = new ArrayList();
    }
    
     public void addMeal(String meal) {
         if (!meals.contains(meal)) {
         meals.add(meal);      
     }
    }
      public void printMeals() {
       if (meals.isEmpty()){
         System.out.println("No Meal Object Found !");
          return;
        }
    for(String meal : meals) {
        System.out.println(meal);
        }
       }
      public void clearMenu(){
          meals.removeAll(meals);
      }
    }
    

提交回复
热议问题