# Java Exercises: Reads an integer n and find the number of combinations of a,b,c and d will be equal to n

## Java Basic: Exercise-216 with Solution

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:

n (1 ≤ n ≤ 50).

Sample Solution:

Java Code:

`````` 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
```

Flowchart: Java Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## Java: Tips of the Day

Java: ConvertInputStreamToString

Converts InputStream to a String.

```public static String convertInputStreamToString(final InputStream in) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte;
int length;
while ((length = in.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
}
```

Ref: https://bit.ly/2N1GDss