A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Java program which reads an integer n and find the number of combinations of a,b,c and d (0 ≤ a,b,c,d ≤ 9) where (a + b + c + d) will be equal to n
Q:

Write a Java program which reads an integer n and find the number of combinations of a,b,c and d (0 ≤ a,b,c,d ≤ 9) where (a + b + c + d) will be equal to n

0

Write a Java program which reads an integer n and find the number of combinations of a,b,c and d (0 ≤ a,b,c,d ≤ 9) where (a + b + c + d) will be equal to n

Input:

a,b,c,d,e,f separated by a single space.
(-1,000 ≤ a,b,c,d,e,f ≤ 1,000)

Expected Output:

Input the number(n):
 5 
Number of combinations of a, b, c and d :
56

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

 import java.util.Scanner;
public class Main {
 
    public static void main(String[] args) {
		System.out.println("Input the number(n):");
        Scanner s = new Scanner(System.in);
        int c = s.nextInt();
        int ans = check(c);
		System.out.println("Number of combinations of a, b, c and d :");
        System.out.println(ans);
    }
    static int check(int c) {
        int ctr = 0;
        for(int i = 0; i < 10; i++) {
            for(int j = 0; j < 10; j++) {
                for(int k = 0; k < 10; k++) {
                    for(int l = 0; l < 10; l++) {
                        if(i + j + k + l == c) {
                            ctr++;
                        }
                    }
                }
            }
        }
        return ctr;
    }
}

Sample Output:

Input the number(n):
 5 
Number of combinations of a, b, c and d :
56

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now