using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
int val, result;
Calc cal = new Calc();
val = 789;
Console.WriteLine("Digit:",val);
result = cal.addFunc(val);
Console.WriteLine("Sum of Digits in {0} = {1}", val, result);
Console.ReadLine();
}
}
class Calc {
public int addFunc(int val) {
if (val != 0) {
return (val % 10 + addFunc(val / 10));
} else {
return 0;
}
}
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/265934.html