Advertisement
desislava_topuzakova

03. Combinations

Jul 16th, 2020
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class t_03 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int counter = 0;
  8.         for (int x1 = 0; x1 <= n; x1++) {
  9.             for (int x2 = 0; x2 <= n; x2++) {
  10.                 for (int x3 = 0; x3 <= n; x3++) {
  11.                     //всички комбинации от числа
  12.                     //x1 + x2 + x3 = n
  13.                     if (x1 + x2 + x3 == n) {
  14.                         //валидна комбинация
  15.                         counter++;
  16.                     }
  17.                 }
  18.             }
  19.         }
  20.         System.out.println(counter);
  21.  
  22.  
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement