# removing 0 from the begining of the array

• 08-21-2008, 05:18 PM
Hayzam
removing 0 from the begining of the array
well , in a problem I'm solving , i have to compare the lengths of 2 arrays ... if they have the same length it will do something , if they don't have it , it will do something else ..

but i failed in a test case that 1 array is 1988 and the other was 0908 ...

how can i remove 0 from the beginning of the array ?!

• 08-21-2008, 05:38 PM
Fubarable
I'm confused: are these supposed to act as Strings or as numbers? If numbers, then perhaps you should parse them as numbers first before comparing.

And how do arrays figure in here? You talk of comparing two arrays, but then in your example you talk of comparing two Strings.

• 08-21-2008, 05:44 PM
Hayzam
i am talking about comparing between 2 arrays from the length point of view ...

array1 = 1999
array2 = 0908

i would like to make array2 = 908 .. can you help me ?
• 08-21-2008, 05:52 PM
Fubarable
Code:

```array1 = 1999 array2 = 0908```
again confusing because this just doesn't make sense. Sorry for being a stickler, but programming is an exercise in precision. If you have a question, you will be best served to communicate it as precisely as possible. Why not show us actual compilable Java code for your example.

e.g.,
Code:

```    // do you mean String?     String s1 = "1999";     String s2 = "0908";         // char array?     char[] charArray1 = s1.toCharArray();     char[] charArray2 = s2.toCharArray();         // ints?     int intValue1 = Integer.parseInt(s1);     int intValue2 = Integer.parseInt(s2);```
• 08-21-2008, 06:46 PM
Hayzam
it is a problem was in the ACM 2007
Quote:

private static void Reverse_Hide_That_Number(int[] input_array)
{
int[] solution = new int[input_array.length];
int[] solution_shifted = new int[input_array.length+1];
int result,flag=0;

for(int i = solution.length;i>0;i--)
{
if(input_array[i-1] < solution_shifted[i])
{
solution[i-1] = input_array[i-1] + 10 - solution_shifted[i] - flag;
flag = 1;

}
else
{
solution[i-1] = input_array[i-1] - solution_shifted[i];
flag = 0;
}

solution_shifted[i-1] = solution[i-1];

}

// checking

if(input_array.length == solution.length -1)
{
// System.out.print(" Accepted ");
for(int i = 0;i<solution.length;i++)
{
// System.out.print(" output : "+ solution[i]);
System.out.print(solution[i]);
}
}
else
{
System.out.println(" IMPOSSIBLE ");
}

}

}
what i need is fixing the if statement at the end of the function to tell impossible if the length of the solution array = the length of the input_array ...
• 08-21-2008, 07:56 PM
Norm
Quote:

array1 = 1999
array2 = 0908

i would like to make array2 = 908 .. can you help me ?
Since the arrays appears to be a String of 4 chars, Then:
array2 = array2.substring(1); // drop leading char
• 08-21-2008, 09:15 PM
Fubarable
actually it seems that he's working with int arrays. You could always check the [0] item to see if it == 0. If so, do an System.ArrayCopy, but don't copy the first item.
• 08-21-2008, 10:02 PM
Fubarable
Abuse reported on Cleaner007 for spamming the forums.