Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FruitOrVegetable {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String product = scanner.nextLine();
- switch (product) {
- case "banana":
- case "apple":
- case "kiwi":
- case "cherry":
- case "lemon":
- case "grapes":
- System.out.println("fruit");
- break;
- case "tomato":
- case "cucumber":
- case "pepper":
- case "carrot":
- System.out.println("vegetable");
- break;
- default:
- System.out.println("unknown");
- break;
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class FruitOrVegetable {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String product = scanner.nextLine();
- String output = switch (product) {
- case "banana", "apple", "kiwi", "cherry", "lemon", "grapes" -> "fruit";
- case "tomato", "cucumber", "pepper", "carrot" -> "vegetable";
- default -> "unknown";
- };
- System.out.println(output);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement