Advertisement
Spocoman

Combinations

Sep 3rd, 2024 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine()),
  7.                 combinations = 0;
  8.  
  9.         for (int a = 0; a <= n; a++) {
  10.             for (int b = 0; b <= n; b++) {
  11.                 for (int c = 0; c <= n; c++) {
  12.                     if (a + b + c == n) {
  13.                         combinations++;
  14.                     }
  15.                 }
  16.             }
  17.         }
  18.  
  19.         System.out.println(combinations);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement