Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Решение със switch:
- using System;
- namespace ForeignLanguages
- {
- class Program
- {
- static void Main(string[] args)
- {
- string contry = Console.ReadLine();
- string print = "";
- switch (contry)
- {
- case "England":
- case "USA":
- print = "English";
- break;
- case "Spain":
- case "Argentina":
- case "Mexico":
- print = "Spanish";
- break;
- default:
- print = "unknown";
- break;
- }
- Console.WriteLine(print);
- }
- }
- }
- Решение с if-else:
- using System;
- namespace ForeignLanguages
- {
- class Program
- {
- static void Main(string[] args)
- {
- string country = Console.ReadLine();
- string language = default;
- if (country == "England" || country == "USA")
- {
- language = "English";
- }
- else if (country == "Spain"|| country == "Argentina" || country == "Mexico")
- {
- language = "Spanish";
- }
- else
- {
- language = "unknown";
- }
- Console.WriteLine(language);
- }
- }
- }
- Решение с тернарен оператор:
- using System;
- namespace ForeignLanguages
- {
- class Program
- {
- static void Main()
- {
- string country = Console.ReadLine();
- Console.WriteLine(country == "England" || country == "USA"? "English"
- : country == "Spain" || country == "Argentina" || country == "Mexico" ? "Spanish"
- : "unknown");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement