Advertisement
Spocoman

06. Foreign Languages

Oct 16th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class ForeignLanguages {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String contry = scanner.nextLine(), print = "";
  7.  
  8.         switch (contry) {
  9.             case "England":
  10.             case "USA":
  11.                 print = "English";
  12.                 break;
  13.             case "Spain":
  14.             case "Argentina":
  15.             case "Mexico":
  16.                 print = "Spanish";
  17.                 break;
  18.             default:
  19.                 print = "unknown";
  20.                 break;
  21.         }
  22.        
  23.         System.out.println(print);
  24.     }
  25. }
  26.  
  27. Solution with new switch(Java 21):
  28.  
  29. import java.util.Scanner;
  30.  
  31. class ForeignLanguages {
  32.     public static void main(String[] args) {
  33.         Scanner scanner = new Scanner(System.in);
  34.         String contry = scanner.nextLine();
  35.  
  36.         String print = switch (contry) {
  37.             case "England", "USA" -> "English";
  38.             case "Spain", "Argentina", "Mexico" -> "Spanish";
  39.             default -> "unknown";
  40.         };
  41.        
  42.         System.out.println(print);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement