标签:变量 今天 file long rgs com mamicode 集群 highlight
今天安装Scala,并学习了Scala语言一些基本的语法,
scala 方法声明格式:def functionName ([参数列表]) : [return type]
例:
object add{
def addInt( a:Int, b:Int ) : Int = {
var sum:Int = 0
sum = a + b
return sum
}
}
Scala的输入语句:val name = StdIn.readLine()
完成了实验二
import scala.io.StdIn
object exercise
{
def main(args:Array[String])
{
println("请输入n")
var n:Long=StdIn.readLine().toLong
var sum=0.0
var a=1.0
while(sum<n)
{
sum=sum+(a+1)/a
a=a+1
}
println("Sn="+sum)
}
}

标签:变量 今天 file long rgs com mamicode 集群 highlight
原文地址:https://www.cnblogs.com/zhang12345/p/12250007.html