I have solidified my knowledge on String related concept( which I think to lot extent but there is always room to learn and grow and practice though). As next progression moving to array challenges now to solidify knowledge on arrays as well then recursion maps as per coding bat order.

Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers.

>> i improved success rate >>
In programming there are really only two success rates 0 and 100. I feel you need to improve more on your ability to think logically than on the various classes and methods with their syntax that Java can provide to generate solutions. In this exercise, there are basically two things to look for - any section of numbers (which I interpret to be a series of numbers) and the sum of all numbers except the ones in those "sections". To determine if a "section" exists, you might start by looking for the first index of 6 then from there finding the first index of 7, eliminating those two numbers and everything in between from the sum. Since there can be more than one such "section" you might have to repeat the search a number of times (now starting from the last found index of 7).

You showed the question along with some sample cases and their answers. Yet you wrote a program without even knowing why their answers are correct. Why in the world would you do that? If you do not know what the program is supposed to do and yet you write a program, then of course you get the wrong answer.
Do you know the answer to this case?
1 1 6 2 3 4 5 8 9 7 1

If so, starting from left to right, by hand, look at one digit at a time, and write down the current sum. While doing that, step through the program one digit at a time. The sumby hand and in your debugger should match as you look at each digit. If it doesn't match, then spend a good deal amount of time thinking about what you did by hand and then keep modifying your code until you get it right. If you still have problems, then post several attempts at getting the solution and tell us on which digit did the program fail to match the sum when you do it by hand.

public class Sum67 { public static void main(String[] args) { // TODO Auto-generated method stub int[] ar = { 1, 2, 2, 6, 99, 99, 7, 3, 9 }; System.out.println("value is" + sum67(ar)); } public static int sum67(int[] nums) { int sum = 0; int len = nums.length; int sixPos=0; int sevenPos=0; int sum1=0; int sum2=0; for (int i = 0; i < len; i++) { if (nums[i] == 6){ sixPos=i; } if (nums[i] ==7){ sevenPos=i; } } for (int i = 0; i < sixPos; i++) { sum1=sum1+nums[i]; } for (int i = sevenPos; i < len; i++) { sum2=sum2+nums[i]; } return sum1+sum2;}}

public int sum67(int[] nums) { int sum = 0; int len = nums.length; int sixPos=0; int sevenPos=0; int sum1=0; int sum2=0; for (int i = 0; i < len; i++) { if (nums[i] == 6){ sixPos=i; } if (nums[i] ==7){ sevenPos=i; } } for (int i = 0; i < sixPos; i++) { sum1=sum1+nums[i]; } for (int i = sevenPos; i < len; i++) { sum2=sum2+nums[i]; } return sum1+sum2;}

1. Loop through each element of given array
2. Find index position of six
3. find index position of seven.
4. find sum1 which is sum of all integers till six index position
5. find sum2 which is sum of all intergers starting from seven index till end
6. return sum of both sextions sum1 plus sum2

You can probably get away with a single pass over the array if you have a boolean that indicates whether you're between a 6 and a 7. The pseudocode of the loop could look like this:

If the current element is a 6, set the boolean to true.

If the boolean is false, add the current element to the sum.

If the current element is a 7, set the boolean to false.

public class Sum67 { public static void main(String[] args) { // TODO Auto-generated method stub //int[] ar = { 1, 2, 2, 6, 99, 99, 7, 3, 9 }; int[] ar = {1, 1, 6, 2, 3, 4, 5, 8, 9, 7, 1};//sixPos 2 sevenPos 9 System.out.println("value is" + sum67(ar)); } public static int sum67(int[] nums) { int sum = 0; int len = nums.length; int sixPos=0; int sevenPos=0; int sum1=0; int sum2=0; for (int i = 0; i < len; i++) { if (nums[i] == 6){ sixPos=i; System.out.println("sixPos is-->"+sixPos); } if (nums[i] ==7){ sevenPos=i; System.out.println("sevenPos is-->"+sevenPos); } } for (int i = 0; i < sixPos; i++) { sum1=sum1+nums[i]; } for (int i = sevenPos+1; i < len; i++) { sum2=sum2+nums[i]; } System.out.println("sum1 is-->"+sum1); System.out.println("sum2 is-->"+sum2); return sum1+sum2;}}

sixPos is-->2
sevenPos is-->9
sum1 is-->2
sum2 is-->1
value is3

xpected Run
sum67([1, 2, 2]) → 5 4 X
sum67([1, 2, 2, 6, 99, 99, 7]) → 5 5 OK
sum67([1, 1, 6, 7, 2]) → 4 4 OK
sum67([1, 6, 2, 2, 7, 1, 6, 99, 99, 7]) → 2 19 X
sum67([1, 6, 2, 6, 2, 7, 1, 6, 99, 99, 7]) → 2 25 X
sum67([2, 7, 6, 2, 6, 7, 2, 7]) → 18 17 X
sum67([2, 7, 6, 2, 6, 2, 7]) → 9 17 X
sum67([1, 6, 7, 7]) → 8 1 X
sum67([6, 7, 1, 6, 7, 7]) → 8 14 X
sum67([6, 8, 1, 6, 7]) → 0 15 X
sum67([]) → 0 0 OK
sum67([6, 7, 11]) → 11 11 OK
sum67([11, 6, 7, 11]) → 22 22 OK
sum67([2, 2, 6, 7, 7]) → 11 4 X
other tests
X

You can probably get away with a single pass over the array if you have a boolean that indicates whether you're between a 6 and a 7. The pseudocode of the loop could look like this:

If the current element is a 6, set the boolean to true.
If the boolean is false, add the current element to the sum.
If the current element is a 7, set the boolean to false.

@gudii9,
It seems like you are making some progress. But, did you do the debugger step-by-step approach with the manual method of your looking at one card at a time, and when the sum differs, then you try to figure out what your program is doing differently than what you are doing by hand.

Given the difficulties you are having with some of these challenges, may I suggest that you first put a question strictly in the algorithms zone and post your pseudo-code (language independent) and explain where it goes wrong when you compare with your manual approach.

Once you get the design right (i.e., the pseudo-code), then it will be easier to code up the challenge.

@awking00,
>> In programming there are really only two success rates 0 and 100.
Heh, you are certainly right for this type of challenge.
But in a free online U.C.S.D. course, you get three chances to fail when you submit your program:
1) incorrect answers
2) program exceeds the time-limit
3) program takes up too much memory
- It's a pretty tough checker with lots of edge corner-cases.

Come to think of it, if the author is getting less errors and figuring out on his own how to correct them, then the challenges are proving very valuable. On the other hand, if the author just shows his progress and gets tips from the experts, then he may understand, but may not know. Knowing is a requirement for most software development positions.

Yeah, the strategy you're using will only work when there's a single 6 and 7 in the input. Have you tried the suggestion I made in this comment? It should work on multiple ranges as well as on single ranges.

public class Sum67 { public static void main(String[] args) { // TODO Auto-generated method stub // int[] ar = { 1, 2, 2, 6, 99, 99, 7, 3, 9 }; // int[] ar = {1, 1, 6, 2, 3, 4, 5, 8, 9, 7, 1};//sixPos 2 sevenPos 9 int[] ar = { 1, 2, 2 };// sixPos 0 sevenPos 0 System.out.println("value is" + sum67(ar)); } public static int sum67(int[] nums) { /* * If the current element is a 6, set the boolean to true. If the boolean is false, add the current element to the sum. If the current element is a 7, set the boolean to false.*/ int sum=0; boolean ind=false; for(int i=0;i<nums.length;i++){ if(nums[i]==6){ ind=true; } if(ind==false){ sum+=nums[i]; } if(nums[i]==7){ ind=true; } } return sum; }}

If the current element is a 6, set the boolean to true.
If the boolean is false, add the current element to the sum.
If the current element is a 7, set the boolean to false

n != 12?