Advertisement
IvanITD

03.AnimalType

Jan 15th, 2024
703
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | Source Code | 0 0
  1. using System.Runtime.CompilerServices;
  2.  
  3. string animalType = Console.ReadLine();
  4.  
  5. //This is the first way of solving the task with the if else statement
  6.  
  7. if (animalType == "dog")
  8. {
  9.     Console.WriteLine("mammal");
  10. }
  11. else if (animalType == "crocodile" || animalType == "tortoise" || animalType == "snake")
  12. {
  13.     Console.WriteLine("reptile");
  14. }
  15. else
  16. {
  17.     Console.WriteLine("unknown");
  18. }
  19.  
  20. //This is the second way of solving the task with the switch case
  21.  
  22. switch (animalType)
  23. {
  24.     case "dog":
  25.         Console.WriteLine("mammal");
  26.         break;
  27.  
  28.     case "crocodile":
  29.     case "tortoise":
  30.     case "snake":
  31.         Console.WriteLine("reptile");
  32.         break;
  33.  
  34.     default:
  35.         Console.WriteLine("unknown");
  36.         break;
  37. }
Tags: C#
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement