
July 15th, 2010, 08:28 PM
|
|
Contributing User
|
|
Join Date: Nov 2008
Posts: 47
Time spent in forums: 7 h 4 m 52 sec
Reputation Power: 0
|
|
|
Simple methods in Scala
"Write a method called squares that takes an integer as its only argument and returns a list of integers that are the squares of the integer up and including the integer argument"
I'm new to Scala, so I'm a little confused on what to do. This is what I have so far:
Code:
def squares(num: Int): List[Int] ={
var inc:Int = 1
var squares:List[Int] = List()
while(inc <= num){
var temp = inc*inc
squares += temp
//inc += 1
}
return squares
}
From what I understand, += can be used to append to a list, but I'm getting a compiler error at that line: type mismatch; found: Inc required: String
But my list is defined as an Int.
I don't understand.
|