Skip to content

Commit 61ebacd

Browse files
committed
Added a practice problem
1 parent c4b10a8 commit 61ebacd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
package com.codefortomorrow.intermediate.chapter11.practice;
22

33
public class Methods {
4+
5+
/**
6+
* Difficulty: 1
7+
*
8+
* Print the first n even integers
9+
* @param n number of even integers to print
10+
*/
11+
public static void printEvens(int n) {
12+
13+
}
414
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
package com.codefortomorrow.intermediate.chapter11.solutions;
22

33
public class Methods {
4+
5+
/**
6+
* Difficulty: 2
7+
*
8+
* Print the first n even integers
9+
* @param n number of even integers to print
10+
*/
11+
public static void printEvens(int n) {
12+
int evens = 0;
13+
int i = 0;
14+
while (evens < n) {
15+
if (i % 2 == 0) {
16+
System.out.print(i + " ");
17+
n++;
18+
}
19+
i++;
20+
}
21+
}
422
}

0 commit comments

Comments
 (0)