I was doing a coding challenge that prints a given text in a zig-zag:
thisisazigzag:
t a g
h s z a
i i i z
s g
So I have my code (not sure if it's right or not yet, but that's not part of the question)
class Main {
public void zigzag(String text, int lines) {
String zigLines = [];
while(lines > 0){
String line = "";
increment = lines+(lines-2);
lines = lines + (" " * (lines-1));
for(int i=(lines-1); i<text.length(); i+=increment) {
line = line + text[i] + (" " * increment);
}
zigLines.add(0, line);
lines--;
}
for(line in zigLines){
println(line);
}
}
static void main(String[] args) {
zigzag("thisisazigzag", 4);
}
}
But when I run the script, I keep getting this error:
groovy.lang.MissingMethodException: No signature of method: static Main.zigzag()
is applicable for argument types: (String, Integer) values: [thisisazigzag, 4]
Possible solutions: zigzag(java.lang.String, int)
And I'm very confused as to the difference between java.lang.String and String and then Integer and int?
Any help or explanation of this would be great!
Thanks.
staticmake it work vs. fail miserably?