scala中计算的的一个小问题,超出Int.maxValue时不会报错
如果小于Int.max时他不会报错
def sumcount(str:String): Int ={ val ints = for(c <- str)yield { println(c.asInstanceOf[Int]) ; c.asInstanceOf[Int]} println(ints.reduce(_*_)) println(Int.MaxValue) ints.sum } sumcount("Hello")
72
101
108
108
111
825152896
2147483647
def sumcount(str:String): Long ={
val ints = for(c <- str)yield { println(c.asInstanceOf[Long]) ; c.asInstanceOf[Long]}
println(ints.reduce(_*_))
println(Int.MaxValue)
println(Long.MaxValue)
ints.sum
}
sumcount("Hello")
学好计算机,走遍天下都不怕