Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nestedLoops_Lab;
- import java.util.Scanner;
- public class Combinations {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int combinationsCount = 0;
- for (int x1 = 0; x1 <= n; x1++) {
- for (int x2 = 0; x2 <= n; x2++) {
- for (int x3 = 0; x3 <= n; x3++) {
- int result = x1 + x2 + x3;
- if (result == n) {
- combinationsCount++;
- }
- }
- }
- }
- System.out.print(combinationsCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement