GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, December 21, 2010

Method In Scala

This is the simplest method example:

scala> def hello() = println("Hello World");
or
scala> def hello() = { println("Holla World"); }

To call it, just type:
scala> hello();

Below is a sample for method with parameters:
scala> def data(name: String, age: Int) = { println("Name: 
     | "+name); println("Age: "+age); }

To call it, type:
scala> data("Lady Gaga",24)
Name: Lady Gaga
Age: 24

Method with return:
scala> def addTwo(x: Int): Int = { return x+2; }
or
scala> def addTwo(x: Int): Int = { x+2; }
Share/Bookmark

No comments:

Post a Comment