File tree 1 file changed +19
-4
lines changed
src/com/github/jonathanbirkey/chapter05
1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change 2
2
* @author : Jonathan Birkey
3
3
* @mailto : jonathan.birkey@gmail.com
4
4
* @created : 28Feb2024
5
- * <p>(Display leap years) Write a program that displays all the leap years, 10 per line, from
6
- * 101 to 2100, separated by exactly one space. Also display the number of leap years in this
7
- * period.
5
+ * <p>(Math: combinations) Write a program that displays all possible combinations for picking
6
+ * two numbers from integers 1 to 7. Also display the total number of all combinations.
7
+ * <p>1 2
8
+ * <p>1 3
9
+ * <p>...
10
+ * <p>...
11
+ * <p>The total number of all combinations is 21
8
12
*/
9
13
package com .github .jonathanbirkey .chapter05 ;
10
14
11
15
public class Exercise43 {
12
16
public static void main (String [] args ) {
13
- // TODO: solve
17
+ int totalCombinations = 0 ;
18
+
19
+ for (int i = 1 ; i <= 7 ; i ++) {
20
+ for (int j = 1 ; j <= 7 ; j ++) {
21
+ if (j != i && j > i ) {
22
+ System .out .printf ("%d %d\n " , i , j );
23
+ totalCombinations ++;
24
+ }
25
+ }
26
+ }
27
+
28
+ System .out .printf ("The total number of all combinations is %d" , totalCombinations );
14
29
}
15
30
}
You can’t perform that action at this time.
0 commit comments