- import java.util.*;
- public class WhoAreYouTest {
- public static void main(String[] args) {
- //input obj
- Scanner in = new Scanner(System.in);
- //start
- System.out.print("What's your name? ");
- String name = in.nextLine();
- System.out.print("and, what's your sex? ");
- String sex = in.nextLine();
- //estimate and output
- if (sex.equals("man")) {
- System.out.print("how old are you? ");
- int age = in.nextInt();
- System.out.println("Hello Mr." + name + ", next year you are " + (age + 1) + ".");
- }
- else if (sex.equals("woman"))
- System.out.println("Hello Miss." + name +", are you have sometimes this weekend?");
- else
- System.out.println("Error: Wrong! The program was close.");
- }
- }
java读取输入(Scanner,equals)
最新推荐文章于 2025-05-13 15:58:56 发布