Advertisement
GabrielHr00

03. Combinations

Feb 8th, 2025
50
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_Lab;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Combinations {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         int combinationsCount = 0;
  10.  
  11.         for (int x1 = 0; x1 <= n; x1++) {
  12.  
  13.             for (int x2 = 0; x2 <= n; x2++) {
  14.  
  15.                 for (int x3 = 0; x3 <= n; x3++) {
  16.  
  17.                     int result = x1 + x2 + x3;
  18.                     if (result == n) {
  19.                         combinationsCount++;
  20.                     }
  21.                 }
  22.  
  23.             }
  24.            
  25.         }
  26.  
  27.         System.out.print(combinationsCount);
  28.        
  29.  
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement