chapter4n1b.java

来自「JAVA源代码程序aashjkjhkjhkjhjkhkj」· Java 代码 · 共 58 行

JAVA
58 行
字号
/* * program to demonstrate a more complicated "if" statement */import java.lancs.* ;public class Chapter4n1b    {    /*     * main     */    public static void main(String[] args) throws Exception	{	// read in values for the Person attributes	BasicIo.prompt("please type in the forename ") ;	String forename = BasicIo.readString() ;	BasicIo.prompt("please type in the surname ") ;	String surname = BasicIo.readString() ;	BasicIo.prompt("please type in the age ") ;        int age = BasicIo.readInteger() ;	BasicIo.prompt("please type in the gender ") ;        String response = BasicIo.readString() ;        int gender ;        if (response.equalsIgnoreCase("male"))            gender = Person.MALE ;        else if (response.equalsIgnoreCase("female"))            gender = Person.FEMALE ;        else            gender = Person.UNKNOWN ;        Person person1 = new Person(forename, surname, age, gender) ;        // output some information about the Person        System.out.print(person1.getForename() + ' ' + person1.getSurname()) ;        System.out.print(" is " ) ;        if (person1.getAge() < 13)            System.out.print("a child") ;        else if (person1.getAge() < 18)            System.out.print("a teenager") ;        else if (person1.getGender() == Person.FEMALE)            {            if (person1.getAge() < 60)                System.out.print("an adult") ;            else                System.out.print("a pensioner") ;            }        else            {            if (person1.getAge() < 65)                System.out.print("an adult") ;            else                System.out.print("a pensioner") ;            }        System.out.println() ;	} // end of method main    } // end of class Chapter4n1b

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?