aufgaben 1 und 2 erfolgreich implementiert
This commit is contained in:
		| @@ -1,4 +1,61 @@ | |||||||
| @main | @main | ||||||
| def main(): Unit = { | def main(): Unit = { | ||||||
|   println("Hello world!") |   println(binKoeff(12,5)) | ||||||
|  |   println(binKoeffRek(12,5)) | ||||||
|  |   println(kontakte) | ||||||
|  |   println(getMail(kontakte)) | ||||||
|  |   println(searchNameByNumber(kontakte,"0123456789")) | ||||||
|  |   println(triagnles(5)) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | //Aufgabe 1 | ||||||
|  | private type kontakt =(String, String, String, String) | ||||||
|  |  | ||||||
|  | val kontakte: List[kontakt] = List(("Johannes","Schmelz","schmelz.johannes@gmx.de","015155550019"), | ||||||
|  |   ("Test","Testificate","test@test.com","0123456789"), | ||||||
|  |   ("Bob","TheBuilder","bob@buildes.com","9876543210")) | ||||||
|  |  | ||||||
|  | var output:List[String] = List() | ||||||
|  | def getMail(adressen:List[kontakt]):List[String] = { | ||||||
|  |   adressen match | ||||||
|  |     case List() => return output | ||||||
|  |     case (vorname,name,mail,tel)::restlist => { | ||||||
|  |       output = mail :: output | ||||||
|  |       getMail(restlist) | ||||||
|  |     } | ||||||
|  |   output.reverse | ||||||
|  | } | ||||||
|  |  | ||||||
|  | def searchNameByNumber(adressen:List[kontakt], searchedNumber:String):String = { | ||||||
|  |   adressen match | ||||||
|  |     case List() => "Not found!" | ||||||
|  |     case (name,surname,mail,tel)::restliste => if(searchedNumber == tel) { | ||||||
|  |       return name+" "+surname | ||||||
|  |     } else { | ||||||
|  |       searchNameByNumber(restliste,searchedNumber) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | //Aufgabe 2 | ||||||
|  | def binKoeff(m:Int, n:Int):Int = { | ||||||
|  |  | ||||||
|  |   def fac(a: Int): Int = { | ||||||
|  |     if (a == 1) return 1 | ||||||
|  |     else a * fac(a - 1) | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if (m >=n & n >= 0) { | ||||||
|  |     fac(m)/(fac(n)* (fac(m-n))) | ||||||
|  |   } else { | ||||||
|  |     System.err.println("Falsche Eingabe der Variablen") | ||||||
|  |     return 0 | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | def binKoeffRek(m:Int,n:Int):Int = { | ||||||
|  |   if (n == 1)  m | ||||||
|  |   else if (m >= n && (n == 0))  1 | ||||||
|  |   else return m * binKoeffRek(m - 1, n - 1) / n | ||||||
|  | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user