Advertisement
IvanITD

09.FruitOrVegetable

Jan 16th, 2024
743
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | Source Code | 0 0
  1. string productName = Console.ReadLine();
  2.  
  3. //Here we solved the assignment with the if else statement
  4. if (productName == "banana" || productName == "apple" || productName == "kiwi" || productName == "cherry" || productName == "lemon" || productName == "grapes")
  5. {
  6.     Console.WriteLine("fruit");
  7. }
  8. else if (productName == "tomato" || productName == "cucumber" || productName == "pepper" || productName == "carrot")
  9. {
  10.     Console.WriteLine("vegetable");
  11. }
  12. else
  13. {
  14.     Console.WriteLine("unknown");
  15. }
  16.  
  17. //Here we solved the assignment with the switch case statement
  18. switch (productName)
  19. {
  20.     case "banana":
  21.     case "apple":
  22.     case "kiwi":
  23.     case "cherry":
  24.     case "lemon":
  25.     case "grapes":
  26.         Console.WriteLine("fruit");
  27.         break;
  28.  
  29.     case "tomato":
  30.     case "cucumber":
  31.     case "pepper":
  32.     case "carrot":
  33.         Console.WriteLine("vegetable");
  34.         break;
  35.  
  36.     default:
  37.         Console.WriteLine("unknown");
  38.         break;
  39. }
Tags: C#
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement