publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){int sum =0;for(int i = start; i <= end; i += step){
sum += i;}return sum;}}
答案2:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){int sum =0;for(int i = start; i <= end; i += step)
sum += i;return sum;}}
答案3:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){return start == end ? end : start > end ?0:SequenceSum(start + step, end, step)+ start;}}
答案4:
using System.Linq;publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){return start > end ?0: Enumerable.Repeat(start,(end - start)/ step +1).Select((x, index)=> x + step * index).Sum();}}
答案5:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){int sum =0;while(start <= end){
sum += start;
start += step;}return sum;}}
答案6:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){if(start>end)return0;int sum=0;for(int i = start;i<=end;i+=step)
sum+=i;return sum;}}
答案7:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){if(start > end){return0;}int sum =0;for(int i = start; i <= end; i += step){
sum += i;}return sum;}}
答案8:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){if(start > end)return0;int sum =0;for(int i = start; i <= end; i += step){
sum += i;}return sum;}}
答案9:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){if(start > end)return0;int sum = start;for(int index = start + step; index <= end; index += step){
sum += index;}return sum;}}
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){int sum =0;if(end >= end){for(int i = start; i <= end; i+= step){
sum += i;}}return sum;}}
答案12:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){if(start > end){return0;}int total =0;for(int i = start; i <= end; i += step){
total += i;}return total;}}
答案13:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){if(start > end)return0;int total =0;for(int i = start; i <= end; i += step)
total += i;return total;}}
答案14:
publicstaticclassKata{publicstaticintSequenceSum(int start,int end,int step){int sum =0;if(start > end)return0;for(int i = start; i <= end; i=i+step){
sum = sum + i;}return sum;}}
序列的总和【难度:1级】:答案1:public static class Kata{ public static int SequenceSum(int start, int end, int step) { int sum = 0; for ( int i = start; i <= end; i += step) { sum...