Java里的if else嵌套语句例子


import java.util.Scanner;
public class if_else3
{
    public static void main(String[] args)
    {
    Scanner s=new Scanner(System.in);
    System.out.println("请输入你的性别(男/女)");
    String sex=s.next();
    if(sex.equals("女"))
    {
    System.out.println("美女你好!");
    System.out.println("请输入你的年龄");
    int age=s.nextInt();
    if(age>=18){System.out.println("女士你好!你的芳龄大于或等于18岁。");}
    else{System.out.println("姑娘你好!你的芳龄小于18岁。");}
    }
    else{System.out.println("帅哥你好!");}
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM