Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class ForeignLanguages {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String contry = scanner.nextLine(), print = "";
- switch (contry) {
- case "England":
- case "USA":
- print = "English";
- break;
- case "Spain":
- case "Argentina":
- case "Mexico":
- print = "Spanish";
- break;
- default:
- print = "unknown";
- break;
- }
- System.out.println(print);
- }
- }
- Solution with new switch(Java 21):
- import java.util.Scanner;
- class ForeignLanguages {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String contry = scanner.nextLine();
- String print = switch (contry) {
- case "England", "USA" -> "English";
- case "Spain", "Argentina", "Mexico" -> "Spanish";
- default -> "unknown";
- };
- System.out.println(print);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement