A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© fenger7 中级黑马   /  2015-10-21 18:30  /  383 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

//
public class IfDemo
{
  public static void main(String[] args)
  {
      int i=1;
      // simple if
      if(i<10)
        System.out.println("i<10");
      if(i>10)
        System.out.println("i>0");
      //if using ablock of code
      if(i==1)
       {
          System.out.println("i equals 1");
          System.out.println("Use a code block to");
          System.out.println("excute more than 1 statement");
        }
      //if-else
      if(i==2)
        System.out.println("i equals 2");
      else
      {
        //a block contains multiple statements
          System.out.println("i dose not equal 2");
          System.out.println("we can execute more");
          System.out.println("than one statement in");
          System.out.println("an if");
       }
      //compound logical expressions
      if(i==1||i==2)
        System.out.println("i equals 1 or 2");
      if(i>0&&i<3)
        System.out.println("i is >0 and <3");
      //nested if can replace compound logical expressions
      if(i>0)
         if(i<3)
           System.out.println("i is >0 and <3");
         //comditional operator
         int j=(i==1)?5:6;
         System.out.println("i equals "+i);

   }
}
      
  

2 个回复

倒序浏览
好无聊啊
回复 使用道具 举报
先这么多废话干啥0.0
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马