扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
000: // Libraries\Factorial.cs 001: using System; 002: 003: namespace Functions 004: { 005: public class Factorial 006: { 007: public static int Calc(int i) 008: { 009: return((i <= 1) ? 1 : (i * Calc(i-1))); 010: } 011: } 012: } |
000: // Libraries\DigitCounter.cs 001: using System; 002: 003: namespace Functions 004: { 005: public class DigitCount 006: { 007: public static int NumberOfDigits(string theString) 008: { 009: int count = 0; 010: for ( int i = 0; i < theString.Length; i++ ) 011: { 012: if ( Char.IsDigit(theString[i]) ) 013: { 014: count++; 015: } 016: } 017: 018: return count; 019: } 020: } 021: } |
000: // Libraries\FunctionClient.cs 001: using System; 002: using Functions; 003: class FunctionClient 004: { 005: public static void Main(string[] args) 006: { 007: Console.WriteLine("Function Client"); 008: 009: if ( args.Length == 0 ) 010: { 011: Console.WriteLine("Usage: FunctionTest ... "); 012: return; 013: } 014: 015: for ( int i = 0; i < args.Length; i++ ) 016: { 017: int num = Int32.Parse(args[i]); 018: Console.WriteLine( 019: "The Digit Count for String [{0}] is [{1}]", 020: args[i], 021: DigitCount.NumberOfDigits(args[i])); 022: Console.WriteLine( 023: "The Factorial for [{0}] is [{1}]", 024: num, 025: Factorial.Calc(num) ); 026: } 027: } 028: } |
FunctionTest 3 5 10 输出: Function Client The Digit Count for String [3] is [1] The Factorial for [3] is [6] The Digit Count for String [5] is [1] The Factorial for [5] is [120] The Digit Count for String [10] is [2] The Factorial for [10] is [3628800] |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者