Advertisement
Spocoman

03. Combinations

Aug 29th, 2024
63
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 Combinations {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int num = Integer.parseInt(scanner.next()),
  7.                 counter = 0;
  8.  
  9.         for (int a = 0; a <= num; a++) {
  10.             for (int b = 0; b <= num; b++) {
  11.                 for (int c = 0; c <= num; c++) {
  12.                     if (a + b + c == num) {
  13.                         counter++;
  14.                     }
  15.                 }
  16.             }
  17.         }
  18.  
  19.         System.out.println(counter);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement