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