Advertisement
grach

Fruit or Vegetable

Mar 28th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FruitorVegetable {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String product = scan.nextLine();
  8.  
  9.         if (product.matches("banana|apple|kiwi|cherry|lemon|grapes")) {
  10.             System.out.println("fruit");
  11.         } else if (product.matches("tomato|cucumber|pepper|carrot")) {
  12.             System.out.println("vegetable");
  13.         } else {
  14.             System.out.println("unknown");
  15.         }
  16.     }
  17. }
  18. /*switch (product){
  19.     case "banana":
  20.     case "apple":
  21.     case "kiwi":
  22.     case "cherry":
  23.     case "lemon":
  24.     case "grapes":
  25.         System.out.println("fruit");
  26.         break;
  27.     case "tomato":
  28.     case "cucumber":
  29.     case "pepper":
  30.     case "carrot":
  31.         System.out.println("vegetable");
  32.         break;
  33.     default:
  34.         System.out.println("unknown");
  35. }
  36.  
  37.     }
  38. }
  39. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement