blob: 1af92a4c8417828b3f91b749584d4bcbec6f2e9e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package se.liu.gusso230.lab1;
public class Exercise2 {
public static void main(String[] args) {
final int min = 10;
final int max = 20;
System.out.println(sumFor(min, max));
System.out.println(sumWhile(min, max));
}
public static int sumFor(int min, int max) {
int res = 0;
for (int i = min; i <= max; i++) {
res += i;
}
return res;
}
public static int sumWhile (int min, int max) {
int res = 0;
int i = min;
while (i <= max) {
res += i;
i++;
}
return res;
}
}
|