Scala programming tutorials
Learn Scala with setup instructions, runnable lessons, and library references covering collections, text, dates, and numerical operations.
Scala core curriculum
Getting started
Decisions and loops
Functions and data
Files and projects
Check a three-digit Armstrong number
object ArmstrongNumber {
def main(args: Array[String]) = {
val input = 153;
var sum = 0;
var armstrongNumber = input;
while (armstrongNumber > 0) {
var i = armstrongNumber % 10;
armstrongNumber = armstrongNumber / 10;
sum += (i * i * i);
}
if (sum == input) {
println("The given number is an Armstrong number");
} else {
println("The given number is not an Armstrong number");
}
}
}
The given number is an Armstrong number