KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > CoverFor


1 package org.hanseltest;
2
3 /**
4  * Class containing all kinds of different uses of for-statements.
5  *
6  * @author Niklas Mehner
7  */

8 public class CoverFor {
9
10     /**
11      * Contains a simple for-loop.
12      * @param n number of times the loop is executed.
13      * @return 5 + n
14      */

15     public int simpleFor(int n) {
16         int result = 5;
17         for (int i = 0; i < n; i++) {
18             result++;
19         }
20
21         return result;
22     }
23
24     /**
25      * Contains a loop with a little more complicated expression.
26      * @param n Possible number of times the loop is run.
27      * @param m Possible number of times the loop is run.
28      * @return 5 + min(n, m)
29      */

30     public int expressionFor(int n, int m) {
31         int result = 5;
32         for (int i = 0; (i < n) && (i < m); i++) {
33             result++;
34         }
35
36         return result;
37     }
38    
39 }
40
Popular Tags