Skip to content

Commit 1e24be7

Browse files
committedMar 13, 2024·
finished exercise 43
1 parent 54643ac commit 1e24be7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed
 

‎src/com/github/jonathanbirkey/chapter05/Exercise43.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22
* @author : Jonathan Birkey
33
* @mailto : jonathan.birkey@gmail.com
44
* @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
812
*/
913
package com.github.jonathanbirkey.chapter05;
1014

1115
public class Exercise43 {
1216
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);
1429
}
1530
}

0 commit comments

Comments
 (0)
Please sign in to comment.