Hi everyone,
I need help for my project in my Java Programming 1 subject. I really don't have an idea on how to go about with this problem. I have started building the code for the CLASS, but didn't bother to post it, cause everytime after I declare the main method, my mind freezes, that's why I decided to ask for your help. This is the problem anyway...
Consider the sequence of digits from 1 through N (where N = 9) in increasing order 1 2 3 4 5 . . . .N, and insert a (+) for addition or a (-) for subtraction or a () [blank] to run the digits together. Now sum the result and see if you get zero.
Write a program that will find all sequences of length N that produces a ZERO SUM.
Test Case 1
Input
7
Output
1 + 2 - 3 + 4 - 5 - 6 + 7 = 0
1 + 2 - 3 - 4 + 5 + 6 - 7 = 0
1 - 2 + 3 + 4 - 5 + 6 - 7 = 0
1 - 2 - 3 - 4 - 5 + 6 + 7 = 0
1 - 23 + 4 + 5 + 6 + 7 = 0
1 - 23 + 45 + 67 = 0
Test Case 2
Input
8
Output
1 + 2 + 3 + 4 - 5 - 6 - 7 + 8 = 0
1 + 2 + 3 - 4 + 5 - 6 + 7 - 8 = 0
1 + 2 - 3 + 4 + 5 + 6 - 7 - 8 = 0
1 + 2 - 3 - 4 - 5 - 6 + 7 + 8 = 0
1 + 23 - 45 + 6 + 7 + 8 = 0
1 - 2 + 3 - 4 - 5 + 6 - 7 + 8 = 0
1 - 2 - 3 + 4 + 5 - 6 - 7 + 8 = 0
1 - 2 - 3 + 4 - 5 + 6 + 7 - 8 = 0
1 - 23 - 4 + 5 + 6 + 7 + 8 = 0
12 - 34 - 56 + 78 = 0
You may test this program by entering the integer from the keyboard.
Thanks, your help is highly appreciated...
I need help for my project in my Java Programming 1 subject. I really don't have an idea on how to go about with this problem. I have started building the code for the CLASS, but didn't bother to post it, cause everytime after I declare the main method, my mind freezes, that's why I decided to ask for your help. This is the problem anyway...
Consider the sequence of digits from 1 through N (where N = 9) in increasing order 1 2 3 4 5 . . . .N, and insert a (+) for addition or a (-) for subtraction or a () [blank] to run the digits together. Now sum the result and see if you get zero.
Write a program that will find all sequences of length N that produces a ZERO SUM.
Test Case 1
Input
7
Output
1 + 2 - 3 + 4 - 5 - 6 + 7 = 0
1 + 2 - 3 - 4 + 5 + 6 - 7 = 0
1 - 2 + 3 + 4 - 5 + 6 - 7 = 0
1 - 2 - 3 - 4 - 5 + 6 + 7 = 0
1 - 23 + 4 + 5 + 6 + 7 = 0
1 - 23 + 45 + 67 = 0
Test Case 2
Input
8
Output
1 + 2 + 3 + 4 - 5 - 6 - 7 + 8 = 0
1 + 2 + 3 - 4 + 5 - 6 + 7 - 8 = 0
1 + 2 - 3 + 4 + 5 + 6 - 7 - 8 = 0
1 + 2 - 3 - 4 - 5 - 6 + 7 + 8 = 0
1 + 23 - 45 + 6 + 7 + 8 = 0
1 - 2 + 3 - 4 - 5 + 6 - 7 + 8 = 0
1 - 2 - 3 + 4 + 5 - 6 - 7 + 8 = 0
1 - 2 - 3 + 4 - 5 + 6 + 7 - 8 = 0
1 - 23 - 4 + 5 + 6 + 7 + 8 = 0
12 - 34 - 56 + 78 = 0
You may test this program by entering the integer from the keyboard.
Thanks, your help is highly appreciated...
Comment