Advertisement
myrdok123

03. Combinations

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