1.基本写法

if

if(逻辑表达式){语句;}else if{语句;else{语句;}

switch

switch(变量){case 常量值:语句;break;default:语句;}

2.举例

if else语句

public class ccc {

    /**
     * @param args
     */
    public static void main(String[] args) {
        
int a = 10

if(a>18)
{
System.out.println("你已经成年");
}
else if(a=18)
{
System.out.println("你刚满十八岁");
}
else
{
System.out.println("你还未成年");
}
         //    
        
        // TODO 自动生成的方法存根

    }

}

2.switch语句

public class ccc {

    /**
     * @param args
     */
    public static void main(String[] args) {
    int a = 5;
    switch(a)
    {
    case 0:
    System.out.println("你是个好人");
    break;
    case 5:
    System.out.println("你不是好人");
    break;
    default:
    System.out.println("输入有误");
    break;
    }
    // TODO 自动生成的方法存根

    }

}

 

相关文章:

  • 2021-11-28
  • 2021-11-29
  • 2021-05-13
  • 2021-10-19
  • 2021-11-27
  • 2021-12-11
  • 2021-08-21
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
相关资源
相似解决方案