Adding Scala examples for Chapter 3 (#28)

* Add files via upload

* Update 01_countdown.scala

* Update 02_greet.scala

* Update 02_greet.scala
This commit is contained in:
chase-g
2017-09-25 20:29:03 -04:00
committed by Aditya Bhargava
parent 495a648a6a
commit 44f8151e11
3 changed files with 29 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
def countdown(i: Int): Int = {
println(i)
//base case
if(i <= 0) return i
//recursive case
else countdown(i-1)
}
countdown(5)

View File

@@ -0,0 +1,16 @@
def greet2(name: String): Unit = {
println("how are you, " + name + "?")
}
def bye(): Unit = {
println("ok bye!")
}
def greet(name: String): Unit = {
println("hello, " + name + "!")
greet2(name)
println("getting ready to say bye...")
bye()
}
greet("adit")

View File

@@ -0,0 +1,5 @@
def fact(x: Int): Int = {
if(x == 1) 1
else x * fact(x-1)
}
println(fact(5))