1
6 public class Valinsum {
7
8
13 public static int valin_summa(int ylaraja) {
14 int i,summa=0;
15 for (i=1; i<=ylaraja; i++)
16 summa += i;
17 return summa;
18 }
19
20 public static int valin_summa_2(int ylaraja) {
21 int i,summa;
22 for (summa=0, i=1; i<=ylaraja; i++)
23 summa += i;
24 return summa;
25 }
26
27 public static int valin_summa_3(int i) {
28 int s;
29 for (s=0; i >= 0; s += i--);
30 return s;
31 }
32
33 public static void main(String[] args) {
34 int summa = valin_summa(100);
35 System.out.println("Summa = " + summa);
36 summa = valin_summa_2(100);
37 System.out.println("Summa = " + summa);
38 summa = valin_summa_3(100);
39 System.out.println("Summa = " + summa);
40 }
41 }
42