Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PersonalTitles {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double age = Double.parseDouble(scanner.nextLine());
- String gender = scanner.nextLine();
- if (gender.equals("m")) {
- if (age < 16) {
- System.out.println("Master");
- } else {
- System.out.println("Mr.");
- }
- } else {
- if (age < 16) {
- System.out.println("Miss");
- } else {
- System.out.println("Ms.");
- }
- }
- }
- }
- Решение с тернарен оператор:
- import java.util.Scanner;
- public class PersonalTitles {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double age = Double.parseDouble(scanner.nextLine());
- String gender = scanner.nextLine();
- System.out.println(age >= 16 ? (gender.equals("f") ? "Ms." : "Mr.") : (gender.equals("f") ? "Miss" : "Master"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement