myrdok123

03. Combinations

Jun 22nd, 2024
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. package NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Combinations_03 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int countCombination = 0;
  12.  
  13.         for (int x1 = 0; x1 <= n; x1++) {
  14.  
  15.             for (int x2 = 0; x2 <= n; x2++) {
  16.  
  17.                 for (int x3 = 0; x3 <= n; x3++) {
  18.                     int combinationResult = x1 + x2 + x3;
  19.                     if (combinationResult == n){
  20.                         countCombination ++;
  21.                     }
  22.  
  23.                 }
  24.             }
  25.         }
  26.  
  27.         System.out.println(countCombination);
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment