File tree Expand file tree Collapse file tree 5 files changed +71
-0
lines changed
src/com/codefortomorrow/intermediate/chapter11 Expand file tree Collapse file tree 5 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ .idea
2
+ .idea /misc.xml
3
+ c4t-java.iml
4
+ .idea /misc.xml
5
+ * .xml
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments