Scala関数式プログラミング(一)

2742 ワード

package PXL.basics

import sun.security.util.Length

/***
 *   Alt + /      
 * def          
 *        ,          ,   ;               ,           
 *              
 * 1.              
 * 2.        ,            
 *          :
 * 1. def     
 * 2.           ,      
 * 3.                  =          ,     Unit
 * 4.                 ,          ,  fib  
 * 5.            
 * 6.             ,       (num:Int*)
 * 7.     1 to 10 : _*       
 * 8.             ,    main       Array[String]     
 * 
 */
object function001 {
  def main(args: Array[String]): Unit = {
    hello("spark",23)
    println(hello("pxl",23))//        (       )
    println("fib num of 10 is "+fib(10))
    println("sum = "+sum( 1 to 10 : _* ))
    println("sumall = "+sumall( 1 to 10 : _* ))
  }
  def hello(name:String,age:Int)={
    println("my name is : "+name)
    println("my age  is : "+age)
    age//          int
  }

  def fib(n:Long):Long={
    if(n<=1) 1
    else
      fib(n-2)+fib(n-1)
  }
  def sum(num:Int*)={
    var result = 0
    for (nu//           
    result //            
  }
  //          
  def sumall(num:Int*):Int = {
    if (num.length==0) 0
    else num.head + sumall(num.tail: _*)//tail        seq,  :_*         
  }
}