fork download
  1. import java.util.Scanner;
  2.  
  3. class Restaurant {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. int count = scan.nextInt();
  8.  
  9. String[] ingredientName = new String[count];
  10. boolean[] vegetarian = new boolean[count];
  11.  
  12. for (int i=0; i<count; i++) {
  13. // Scan ingredient, price, vegetarian/not, and calories
  14. ingredientName[i] = scan.next();
  15. vegetarian[i] = scan.nextBoolean();
  16. }
  17.  
  18. System.out.println("Number of vegetarian ingredients: " + getVegetarian(vegetarian));
  19. }
  20.  
  21. public static int getVegetarian(boolean[] list) {
  22. int count = 0;
  23. for (int i=0; i<list.length; i++) {
  24. if (list[i] == true) {
  25. count++;
  26. }
  27. }
  28. return count;
  29. }
  30.  
  31. }
Success #stdin #stdout 0.16s 35872KB
stdin
3
Potato
true
Apple
true
Steak
false
stdout
Number of vegetarian ingredients: 2