yovkovbpfps

Nested Loops Lab Combination

Apr 15th, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class MyClass {
  3. public static void main(String[] args) {
  4. Scanner console = new Scanner(System.in);
  5. int n = Integer.parseInt(console.nextLine());
  6. int counter = 0;
  7. for(int i = 0; i <= n; i++) {
  8. for(int k = 0; k <= n; k++) {
  9. for(int j = 0; j <= n; j++) {
  10. for(int s = 0; s <= n; s++) {
  11. for(int d = 0; d <= n; d++) {
  12. int combinations = i + k + j + s + d;
  13. if (combinations == n) {
  14. counter++;
  15. }
  16. }
  17. }
  18. }
  19. }
  20. }
  21. System.out.println(counter);
  22. }
  23. }
Add Comment
Please, Sign In to add comment