您当前的位置: 首页 >  段智华 scala

周末班补充视频Scala第2课:动手编写和运行自己的第一个Scala函数式编程的实例.

段智华 发布时间:2016-06-04 20:13:53 ,浏览量:3

周末班补充视频Scala第2课:动手编写和运行自己的第一个Scala函数式编程的实例.

 

 

package com.dtspark.scala.functional.basics

object MyFirstFunctionalAPP {
  def add(x:Int,y:Int): Int = {
    x+y
 }
     def sub(x:Int,y:Int):Int ={
      
       x-y
     }
 
      def formatResult(x:Int,y:Int,f:(Int,Int)=>Int) :String= {
      
       println("the result test : " + f(x,y))
        "the result : %d ".format(f(x,y))
       
       
      }
 
  def main (args:Array[String]):Unit = {
   
    println(formatResult(1,2,add))
    println(formatResult(1,2,sub))
  }
 
 
}

 

测试 结果

 

the result test : 3
the result : 3
the result test : -1
the result : -1

关注
打赏
查看更多评论

段智华

暂无认证

  • 3浏览

    0关注

    1232博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录