-3

I'm using java bluejay trying to solve a recursion problem.

The problem : given an array of natural numbers (higher then 0) and an int, the method needs to tell if the array consist of a way to sum up the numbers to get the given int. example {4,5} int = 13 >> 4+4+5 = 13 = true example {4,5} int = 3 >>> false.

The 2nd problem is that when i use my main it says "cannot find symbol - method isSumOf(int[],int) although i do have this kind of method...

Here is my classes:

public class Ex14
{
    static int allways;
    static int index = -1;

    public static boolean isSumOf(int[] s, int n){
        if(index == -1) index = s.length - 1;
            return isSumOf(s, n, index);
    }

    private static boolean isSumOf(int[] s, int n, int index){
        int temp = s[index];   
        if(allways == n) {return true;}
        if(allways > n && index != 0) {allways -= temp + s[index - 1]; 
        if(allways / s[index - 1] == s.length) index --;}
        if(allways > n && index == 0) return false;
        if(allways < n) allways += temp; return isSumOf(s, n);
    }
}

My main class:

public class bdikot
{ 
    public static void main(String[] args){
    int [] hi= new int[1];
    hi[0]=3;


    System.out.println(isSumOf(hi,7));}
}

Thanks in advance Asaf :-) .

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93

1 Answers1

0

For your second problem, I think you need to change:

System.out.println(Ex14.isSumOf(hi,7));

Since isSumOf exists in a different class than your main method.

Also you might want to take a look at:

https://en.wikipedia.org/wiki/Programming_style

https://google.github.io/styleguide/javaguide.html

Since following these will make your code easier to read for others.

Malphrush
  • 328
  • 3
  • 12