Advertisement
veronikaaa86

3. Комбинации

Feb 11th, 2023
1,319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. package nestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P03Combination {
  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 count = 0;
  12.         for (int i = 0; i <= n; i++) {
  13.             for (int j = 0; j <= n; j++) {
  14.                 for (int k = 0; k <= n; k++) {
  15.                     int sum = i + j + k;
  16.                     if (sum == n) {
  17.                         count++;
  18.                     }
  19.                 }
  20.             }
  21.         }
  22.         System.out.println(count);
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement