Skip to content

Commit a5658c9

Browse files
committed
commit de somme range
1 parent 7e61805 commit a5658c9

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

bin/sum/range/Solution.class

851 Bytes
Binary file not shown.

src/sum/range/Solution.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package sum.range;
2+
3+
public class Solution {
4+
5+
/**
6+
*
7+
* @param array
8+
* @param n1
9+
* @param n2
10+
* @return la somme des elements du tableau entre les indices n1 et n2
11+
* on suppose ici que n1<= n2 et n2< array.length
12+
*/
13+
public static int calc(int[] array , int n1 , int n2) {
14+
int somme=0;
15+
if(n1==n2)
16+
return array[n1];
17+
else {
18+
for(int i=n1;i<=n2;i++) {
19+
somme+=array[i];
20+
}
21+
return somme;
22+
}
23+
}
24+
public static void main(String[] args) {
25+
int tableauEntier[] = {0,1,2,3,4,5,6,7,8,9};
26+
27+
System.out.println(calc(tableauEntier,0,9));
28+
29+
}
30+
31+
}

0 commit comments

Comments
 (0)