Created
May 28, 2011 17:34
-
-
Save oluies/997054 to your computer and use it in GitHub Desktop.
print mult table 1 to 12 as a square
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// print mult table 1 to 12 as a square | |
for( a <- (1 to 12); b <- (1 to 12)){ | |
print("%4s".format(a*b)) | |
if (b == 12) println("") | |
} | |
println("") | |
// is sugar for | |
(1 to 12).foreach( a => (1 to 12).foreach( b => { | |
print("%4s".format(a*b)) | |
if(b == 12) println("") | |
})) | |
println("") | |
// this should be as fast as a java equivelent | |
var a = 1; var b = 1; | |
while(a <= 12){ | |
b = 1 | |
while(b <= 12){ | |
print("%4s".format(a*b)) | |
if(b == 12) println("") | |
b += 1 | |
} | |
a += 1 | |
} | |
println("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment