Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Objects;
- import java.util.Scanner;
- public class AnimalType {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String animal = scanner.nextLine();
- if (Objects.equals(animal, "dog")) {
- System.out.println("mammal");
- } else if
- (Objects.equals(animal, "crocodile")
- || Objects.equals(animal, "tortoise")
- || Objects.equals(animal, "snake")) {
- System.out.println("reptile");
- } else {
- System.out.println("unknown");
- }
- }
- }
- Решение с switch:
- import java.util.Scanner;
- public class AnimalType {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String animal = scanner.nextLine();
- switch (animal) {
- case "dog":
- System.out.println("mammal");
- break;
- case "crocodile":
- case "tortoise":
- case "snake":
- System.out.println("reptile");
- break;
- default:
- System.out.println("unknown");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement