/**
*
* Ashish Patel
* e: ashishsushilPatel@gmail.com
* w: https://ashish.me
*
*/
public class SumOfDigits {
static int func(int n) {
if (n == 0) {
return 0;
}
return n % 10 + func(n / 10);
}
public static void main(String[] args) {
int result = func(501);
System.out.println(result);
}
}
Created 2021-10-19T10:51:48+01:00, updated 2021-10-21T02:18:53+01:00 · History · Edit