You start counting arrays with the number 0,so the first element in an array is the 0th element. If an array has three elements a, b, c. The indexes would be 0, 1, 2 but the length would be 3. Therefore: If you want to loop through all the indices...

What you are missing is, that there could be more than one odd number on the right side of your zero and you need to pick the largest one. Edit: And you also need to reset 'acum'. I updated my suggestion :) Here's a suggestion: public int[] zeroMax(int[] nums) {...

The first condition checks for the minimum length of string which should be 3. So "bad" and "xba" passes the first condition. Lets go with bad first. The second condition has two OR clauses and string "bad" satisfies the first of two OR clauses at line no 3. And hence...

Over-complicating? Yes, you really are :-) I would just be using the much simpler: public String seeColor (String color) { if (color.startsWith("red")) return "red"; if (color.startsWith("blue")) return "blue"; return ""; } The following complete program shows it in action: public class Test { public static String seeColor (String color) {...

I think your problem is when you actually compute the average from the length. Here's how I did it; don't feel pressured to use it... int average( int[] scores, int start, int end ) { int sum = 0; for ( int i = start; i < end; ++i )...

nums[nums.length-1]gives you the last element CONTAINED in the array Array can be of int, char, or whatever you want and the element is the same kind of the array. nums.length-1 gives you the length of the array minus 1 It always is a int: the last position. About code reference,...

Here's mine: public static String starOut(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '*') continue; if (i > 0 && s.charAt(i - 1) == '*') continue; if (i < s.length() - 1 && s.charAt(i + 1) ==...

In Case you need a for loop you can go with the below code. public static boolean check(String s1,String s2) { boolean result = false; if(s1.length() >= s2.length()) { result = compare(s1, s2); } else { result = compare(s2,s1); } return result; } public static boolean compare(String s1,String s2) {...

The problem with your solution is that you are simply returning false in case the string in question has odd length Which is actually not true, the pass use-cases for this task can be mathematically divided like below: 1)With xyz present in the middle and there is a string of...

The fix made the flag was not being set to false in the outer loop the fix is not visible here