21.scala编程思想笔记——条件表达式

21.scala编程思想笔记——条件表达式

欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/50445755
源码下载连接请见第一篇笔记。

典型的模式从if开始,后面按照需要跟着多个else if子句。

然后以else结尾。

例如:

import com.atomicscala.AtomicTest._

 

def checkTruth(

  exp1:Boolean,exp2:Boolean):String = {

  if(exp1&& exp2) {

    "Bothare true"

  }

  else if(!exp1&& !exp2) {

    "Bothare false"

  }

  else if(exp1){

   "First: true, second: false"

  }

  else {

   "First: false, second: true"

  }

}

 

checkTruth(true || false, true) is

  "Bothare true"

checkTruth(1 > 0 && -1 < 0, 1 == 2) is

  "First:true, second: false"

checkTruth(1 >= 2, 1 >= 1) is

  "First:false, second: true"

checkTruth(true && false,false &&true) is

"Both are false"

执行如下:

[root@localhost examples]# scala -nocompdaemonCheckTruth.scala

Both are true

First: true, second: false

First: false, second: true

Both are false

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值