Skip to content

Commit 694bac7

Browse files
authored
Merge pull request #5 from code-for-tomorrow/chapter11_achintya
Updated Gitignore + Added Practice Problem for Ch 11
2 parents 63e9762 + 72cb957 commit 694bac7

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
.idea/misc.xml
3+
c4t-java.iml
4+
.idea/misc.xml
5+
*.xml
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codefortomorrow.intermediate.chapter11.practice;
2+
3+
public class Average {
4+
/**
5+
* Difficulty: 1
6+
*
7+
* Returns the average of two doubles
8+
* @param a the first double
9+
* @param b the second double
10+
* @return average
11+
*/
12+
public static double average(double a, double b) {
13+
return 0.0; // TODO: Fix!
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.codefortomorrow.intermediate.chapter11.practice;
2+
3+
public class PrintEvens {
4+
/**
5+
* Difficulty: 1
6+
*
7+
* Print the first n even integers
8+
* (consider 0 an even number)
9+
* @param n number of even integers to print
10+
*/
11+
public static void printEvens(int n) {
12+
// write code here
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codefortomorrow.intermediate.chapter11.solutions;
2+
3+
public class Average {
4+
/**
5+
* Difficulty: 1
6+
*
7+
* Returns the average of two doubles
8+
* @param a the first double
9+
* @param b the second double
10+
* @return average
11+
*/
12+
public static double average(double a, double b) {
13+
return (a + b) / 2;
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.codefortomorrow.intermediate.chapter11.solutions;
2+
3+
public class PrintEvens {
4+
/**
5+
* Difficulty: 2
6+
*
7+
* Print the first n even integers
8+
* (consider 0 an even number)
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+
evens++;
18+
}
19+
i++;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)