中华考试网·阅读新闻
编程开发 > JAVA > 文章内容

JAVA编程入门教程(17)

2015-11-19编辑:guomu

if嵌套结构

判断男女:

import java.util.*;

public class Test{

       public static void main(String[] args){

              Scanner in=new Scanner(System.in);

              System.out.println("请输入你的性别?(男/女)");

              String  sex=in.next();

              if(sex.equals("男")){

                     System.out.println("你的年纪是多少?");

                     int age=in.nextInt();

                     if(age>18){

                            System.out.println("恭喜成年了");

                     }else{

                            System.out.println("还未成年");}           

              }

              else{ 

                     System.out.println("原来是个女孩");

              }

                           

       }

}

JAVA编程入门教程(16)
咨询热线:4000-525-585(免长途费)