Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
.idea/misc.xml
c4t-java.iml
.idea/misc.xml
*.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.codefortomorrow.intermediate.chapter11.practice;

public class Average {
/**
* Difficulty: 1
*
* Returns the average of two doubles
* @param a the first double
* @param b the second double
* @return average
*/
public static double average(double a, double b) {
return 0.0; // TODO: Fix!
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codefortomorrow.intermediate.chapter11.practice;

public class PrintEvens {
/**
* Difficulty: 1
*
* Print the first n even integers
* (consider 0 an even number)
* @param n number of even integers to print
*/
public static void printEvens(int n) {
// write code here
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.codefortomorrow.intermediate.chapter11.solutions;

public class Average {
/**
* Difficulty: 1
*
* Returns the average of two doubles
* @param a the first double
* @param b the second double
* @return average
*/
public static double average(double a, double b) {
return (a + b) / 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.codefortomorrow.intermediate.chapter11.solutions;

public class PrintEvens {
/**
* Difficulty: 2
*
* Print the first n even integers
* (consider 0 an even number)
* @param n number of even integers to print
*/
public static void printEvens(int n) {
int evens = 0;
int i = 0;
while (evens < n) {
if (i % 2 == 0) {
System.out.print(i + " ");
evens++;
}
i++;
}
}
}