-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunciones.scala
More file actions
38 lines (37 loc) · 941 Bytes
/
funciones.scala
File metadata and controls
38 lines (37 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
object Persona {
def saludar(nombre: String): Unit = {
println(s"Hola ${nombre}")
}
def mostrarSuma(x: Int): Unit = {
println(x)
}
def sumarEnteros(x: Int, y: Int): Int = {
x + y
}
def decirDia(d: String): Unit = {
println(d match {
case "l" => "Lunes"
case "m" => "Martes"
case "mi" => "Miercoles"
case "j" => "Jueves"
case "v" => "Viernes"
case "s" => "Sabado"
case "d" => "Domingo"
case _ => "No existe"
})
}
def cuadrado(x: Int): Int = x * x
def listaNumeros(): Unit = {
val numeros = List(10, 17, 20, 22, 40)
val edades = List(List(10, 11, 12), List(13, 14, 15), List(16, 17, 18))
numeros.apply(3)
numeros.length
println(edades.flatten)
println(numeros.map { x => cuadrado(x)})
}
}
//Evaluaciones
Persona.saludar("Webexz!")
val resultado = Persona.sumarEnteros(5, 10)
Persona.mostrarSuma(resultado)
Persona.decirDia("r")