Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* levelezősök
  + Adator. prog.
  + feladatsor
  + quick link

teaching assets


Félévek

* 2024/25/1
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

functions, methods

#############################

Functions

def double(n: Int): Int = {
  2 * n
}

val x = 4
println(double(x))    // 8

If the function's body is just one expression, then you can omit the curly braces:

def double(n: Int): Int = 2 * n    // equivalent with the previous

Methods

def hello(name: String) {
  println("Hello, %s!".format(name))
}

Notice that its return type is missing and there is no "=" sign before the opening brace. This is a method, not a function.


The code above is actually a shorthand for the following. Here it is explicitly stated that its return type is Unit (i.e. void):

def hello(name: String): Unit = {
  println("Hello, %s!".format(name))
}
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2015 March 15, 12:02