I am trying to write a brief code that would read a few lines from console. This is my code:
System.in.withReader {
int a = it.readLine() as int
(1..a).each {
int b = it.readLine() as int
def sum = 0
(0..(b-1)).each {d ->
sum+=(-1)^d/(2*d+1)
}
println sum/4
}
}
This is input from the console:
1
20
And this is the error I get:
java.lang.Integer.readLine() is applicable for argument types: () values: []
I have a feeling that somehow Groovy does not get inputs from console. When I tried debugging it did not allow me to enter anything into console.