scala> def hello() = println("Hello World");
or
scala> def hello() = { println("Holla World"); }
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: 24Method with return:
scala> def addTwo(x: Int): Int = { return x+2; }
or
scala> def addTwo(x: Int): Int = { x+2; }
No comments:
Post a Comment