Advertisement
damesova

Combination - Java

Dec 13th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. package NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Combination {
  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 counter = 0;
  12.  
  13. for (int i = 0; i <= n; i++) {
  14. for (int j = 0; j <= n; j++) {
  15. for (int k = 0; k <= n; k++) {
  16. for (int l = 0; l <= n; l++) {
  17. for (int m = 0; m <= n; m++) {
  18. if (i + j + k + l + m == n)
  19. counter++;
  20. }
  21. }
  22. }
  23. }
  24. }
  25. System.out.println(counter);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement