Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-21-2008, 07:18 PM
Member
 
Join Date: May 2008
Posts: 7
Hayzam is on a distinguished road
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 ?!

Thanks in Advance

Last edited by Hayzam : 08-21-2008 at 07:42 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-21-2008, 07:38 PM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 876
Fubarable is on a distinguished road
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.

Please clarify.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-21-2008, 07:44 PM
Member
 
Join Date: May 2008
Posts: 7
Hayzam is on a distinguished road
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 ?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-21-2008, 07:52 PM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 876
Fubarable is on a distinguished road
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);

Last edited by Fubarable : 08-21-2008 at 07:55 PM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-21-2008, 08:46 PM
Member
 
Join Date: May 2008
Posts: 7
Hayzam is on a distinguished road
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 ...
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-21-2008, 09:56 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-21-2008, 11:15 PM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 876
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-22-2008, 12:02 AM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 876
Fubarable is on a distinguished road
Abuse reported on Cleaner007 for spamming the forums.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using escape sequence to find rows begining with % Java Tip Java Tips 0 02-14-2008 12:00 PM
image removing Triss New To Java 3 01-20-2008 10:27 PM
Removing characters kDude New To Java 3 12-03-2007 04:38 AM
removing duplicates from arrays bugger New To Java 3 11-13-2007 08:11 PM
Help with removing somthing once inputed. fegiflu New To Java 8 07-27-2007 12:58 AM


All times are GMT +3. The time now is 02:20 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org