I need to create a recursive method that takes a number as input that will be the sum and find all the options to add three native numbers so they will be equal to this number. e.g if the input is 5, I will need to find all the 5 options [(1,1,3),(1,2,2),(1,3,1),(2,2,1),(3,1,1)]. max number is […]
Categories
Find 3 numbers that are sum up to a given number
- Post author By Full Stack
- Post date January 16, 2021
- No Comments on Find 3 numbers that are sum up to a given number
- Tags "x3"], { "x2": 1, 1, 1)]. max number is 30. the method should print the options, 2, 3, and give back the number of options: public static int solutions(int num) { if(num 30) return 0; return solution, I need to create a recursive method that takes a number as input that will be the sum and find all the options to add three native numbers so, I will need to find all the 5 options [(1, int num) { if(x1 > 10 || x2 > 10 || x3 > 10) return 0; if (x1+x2+x3 != num) { return solutions(x1 + 1, int x2, int x3, num); } else { System.out.println(x1 + "+" + x2 +"+" + x3); return 1; } } this code gives me too many answe, num); } private static int solutions(int x1, num)+ solutions(x1, x2, x3[-1