How to print a filled rectangle in Scala? -
print filled rectangle, filling // specified number of columns , rows of character inchar, // surrounded border made of character edgechar.
i'm confused understand want make multiple loops. have far nested loop outer loop number of columns , inner loop number of rows. i'm confused how print specific number of dashes , +s , loop content. , how , width , height come play
for (k=1; k <= columns; columns >= k++) { (i = 1; <= rows >= i++) { println(edgechar) //println(+-) } (i = 1; <= rows; i++){ (j) println(edgechar) } (j = 1; j <= columns; j++){ println(inchar) } (k, k<=columns+2;k++){ println(edgechar)
this being scala, want map , play lists rather loops. here's working example (paste in scala repl):
val ec="@" val cc="x" val cols=8 val rows=5 ((ec*(cols+2)) +: range(0,rows).map( _ => ec+cc*cols+ec) :+ (ec*(cols+2)) ).mkstring("\n") this results in:
res22: string = @@@@@@@@@@ @xxxxxxxx@ @xxxxxxxx@ @xxxxxxxx@ @xxxxxxxx@ @xxxxxxxx@ @@@@@@@@@@
Comments
Post a Comment