Question: I need to write at java a recursive static method that accepts as a parameter a positive integer and returns several solutions to the equation
I need to write at java a recursive static method that accepts as a parameter a positive integer and returns several
solutions to the equation
x1 + x2 + x3 = digit
The three x's are integers and positive numbers between 1 to 10
The method should also print these solutions (no matter the order of printing)
Example 1:
If digit = 3 returns the value 1 there is only one solution to the equation: x1 = 1, x2 = 1, x3 = 1
And the method will print
output:
1 + 1 + 1
value: 1
Example 2:
If digit = 5 return the value 6 and print the following solutions:
output:
1 + 1 + 3
1 + 2 + 2
1 + 3 + 1
2 + 1 + 2
2 + 2 + 1
3 + 1 + 1
value: 6
The method should be recursive without using loops also any auxiliary method cannot be with loops.
Not used java package
It is possible to use overloading and not have to optimize the method
I started the some code:
public static int sum(int digit){
if (digit <3 || digit> 30)
return 0;
}
I would appreciate your assistance
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
