Scala循环及判断
if条件判断
for循环
while循环
动手实践
1.水仙花数是指其个位、十位、百位三个数的立方和等于这个数本身,请用Scala编程求出1000内所有水仙花数
for(a10<-100 until 1000) {
var bai = a10%1000/100
var ten = a10%100/10
var gw = a10%10
var sum = bai*bai*bai +
ten*ten*ten +
gw*gw*gw
if (sum == a10) {
println("Value of Narcissistic number:"+a10)
}
}
2.打印九九乘法表
for{
i <- 1 to 9
j <- 1 to i
} yield {
print(j + " * " + i + " = " + i * j +" ")
if(i == j) println("")
i*j
}