Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
object HelloWorld {
def main(args: Array[String]) {
// val a = 1 to 10
// def func(x:Int):Int = {
// return x*2
// }
// val b = func(2)
// println(b)
// val c = a.map(func)
// println(c)
// val d = func(_)
// println(d(10))
println("Pascal's Triangle")
var n = 11
for (row <- 0 to 10) {
var a = " " * n
print(a)
n = n - 1
for (col <- 0 to row) {
print(pascal(col, row) + " ")
}
println()
}
/**
* Exercise 1: Pascal's Triangle
*/
def pascal(c: Int, r: Int): Int = {
if (c == 0 || c == r) 1
else
pascal(c - 1, r - 1) + pascal(c, r - 1)
}
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more