- To print total number of digits in a number
User Input: 45
Output:
Sum of total number of digits : 9
import java.util.Scanner
fun main(args: Array<String>) {
print("Enter your number : ")
val userInput = Scanner(System.`in`)
var num:Int = userInput.nextInt()
var sum:Int = 0
while(num!=0) {
sum+=num%10
num/=10;
}
println("Sum of total number of digits : $sum")
}
Enter Your number : 1132 Sum of total number of digits : 7Program
Coming Soon !
QuickIn order to succeed you must fail, so that you know what not to do the next time.