if语句嵌套作业 以及个人理解

/*题目 从键盘上接受天气信息,
1 =雨天
0 =晴天
同时从键盘上接受性别信息
1=男
0=女
要求
当天气是雨天时
男:打一把大黑伞
女:打一把小花伞
当天气是晴天
男:出去玩耍
女:待在家
使用if语句嵌套方式*/
      public class if语句{
          public static void main(String[] args){
      java.util.Scanner s = new java.util.Scanner(System.in);
          System.out.println("输入0=晴天,输入1=雨天");
      int a = s.nextInt();
          System.out.println("输入1=男,输入0=女");
      int b =s.nextInt();
      if (a==1){

          //System.out.println("yutian");
      if (b==1){
      //男
          System.out.println("打一把大黑伞");
      }else if (b==0){

          System.out.println("打一把小花伞");
      }
      }else if (a==0){
          //System.out.println("qingtian");
      if (b==1){
          System.out.println("出去玩");
      }else if (b==0)
      {
          System.out.println("待在家");
       }
      }
     } 

    }

 

 

 

 

 

 

public class 信息{
public static void main(String[] args){
java.util.Scanner s = new java.util.Scanner(System.in);
System.out.println("输入0=晴天,输入1=雨天");
int a = s.nextInt();
System.out.println("输入1=男,输入0=女");
int b =s.nextInt();



if (a==1)
{
System.out.println("雨天");
if (b==1)
{
System.out.println("打一把黑伞");
}else if (b==0)
{
System.out.println("打一把花伞");
}
}else if (a==0)
{
System.out.println("晴天");
if (b==1)
{
System.out.println("出去玩");
}else if (b==0)
{
System.out.println("待在家");
}

}
}
}

 

 

 


      if ()
      {
        /* if ()
        {
        }else if ()
        {
        } */嵌套的语句 判断对象不是if就是 elseif 两个判断选择 可以无限套娃
      }else if ()
        {
        /* if ()
        {
        }else if ()
        {
        } */嵌套的语句 判断对象不是if就是 elseif 两个判断选择 可以无限套娃
      }

posted @ 2020-08-26 21:50    阅读(388)  评论(0)    收藏  举报