Advertisement
veronikaaa86

03. Combinations

Nov 6th, 2021
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. package nestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P03Combinations {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int n = Integer.parseInt(scanner.nextLine());
  10.  
  11. //0 -> 25
  12. //0 + 0 + 25 == 25
  13.  
  14. int countValidComb = 0;
  15. for (int i = 0; i <= n; i++) {
  16. for (int j = 0; j <= n; j++) {
  17. for (int k = 0; k <= n; k++) {
  18. int sum = i + j + k;
  19.  
  20. if (sum == n) {
  21. countValidComb++;
  22. }
  23. }
  24. }
  25. }
  26.  
  27. System.out.println(countValidComb);
  28. }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement