I am trying to get four input from the user and try to find pairs that equal to a prime number just by using user defined methods. i din reach the prime step yet. But before that i ran into a problem. So jus to check the sum I TRIED printing it out in the method called sumPair6 but it prints zero, so the sum is returning 0 for everything. don't know what mistake am i doing. I go t rid of the initial 0 too but still doesn't not work
How do you know it's returning 0? You don't seem to save those values anywhere...
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
posted 2 years ago
fred rosenberger wrote:How do you know it's returning 0? You don't seem to save those values anywhere...
I ran this program and when i put the input. just to check what is the sum, I printed out and it printed 0
Enter positive integer :1 Enter positive integer :2 Enter positive integer :3 Enter positive integer :4
You are passing in the value contained in the static variable "sum1". However, your parameter, also named "sum1" is a local copy so that when you assign a value to it on line 69 you are changing only the local "sum1" not the static "sum1".
On the other hand you return the local "sum1" on line 70 but further up in the program where you call this method you are not doing anything with the returned value.