Created
December 6, 2012 23:31
-
-
Save mepcotterell/4229402 to your computer and use it in GitHub Desktop.
Armstrong
This file contains 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
public class Armstrong { | |
public static void main(String[] args) { | |
for (int a = 0; a < 9; a++) { | |
for (int b = 0; b < 9; b++) { | |
for (int c = 0; c < 9; c++) { | |
int n = a * 100 + b * 10 + c; | |
int a3 = a * a * a; | |
int b3 = b * b * b; | |
int c3 = c * c * c; | |
if (a3 + b3 + c3 == n) System.out.println(n); | |
} // for | |
} // for | |
} // for | |
} // main | |
} // Armstrong |
This file contains 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
object Armstrong extends App{ | |
for (a <- 0 to 9; b <- 0 to 9; c <- 0 to 9) { | |
val n = a * 100 + b * 10 + c | |
val a3 = a * a * a | |
val b3 = b * b * b | |
val c3 = c * c * c | |
if (a3 + b3 + c3 == n) println(n) | |
} // for | |
} // Armstrong |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment