Results 1 to 2 of 2
- 08-01-2007, 05:35 AM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Remove the bucket represented by the int from array
Hi, I need to take a char array and an int as parameters and remove the bucket represented by the int from the array. this is what i have so far
I'm not sure about this partJava Code:static char[] removeArray (char[] x, int e) { char[] result = new char[x.length-1]; for (int i = 0; i < result.length; i++) { if (i == e) result[e] = if (i < e) result[i] = x[i]; if (i > e) result[i] = x[i+1]; } }
how do i tell it to get rid of the char at int e?Java Code:if (i == e) result[e] =
Thanks
- 08-01-2007, 08:55 AM #2
Java Code:public static void main(String[] args) { String s = "Hello World"; char[] chars = s.toCharArray(); print(chars, " chars"); char[] reduced = removeElement(chars, 9); print(reduced, "reduced"); } static char[] removeElement(char[] x, int e) { char[] result = new char[x.length-1]; for (int i = 0, k = 0; i < x.length; i++) { if (i == e) continue; result[k++] = x[i]; } return result; } private static void print(char[] array, String s) { System.out.print(s + " = ["); for(int j = 0; j < array.length; j++) { System.out.print(array[j]); if(j < array.length-1) System.out.print(", "); } System.out.print("]\n"); }
Similar Threads
-
how to remove an image icon
By cecily in forum Advanced JavaReplies: 1Last Post: 08-05-2007, 04:25 AM -
how to remove whitespaces in a text
By christina in forum New To JavaReplies: 2Last Post: 08-03-2007, 05:24 PM -
Is there a way to remove an option from optionsCollection?
By schu777 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-02-2007, 09:47 PM -
how to remove an object from the array list
By cecily in forum New To JavaReplies: 3Last Post: 08-02-2007, 02:26 PM -
how to remove an old version of JDK
By tommy in forum New To JavaReplies: 2Last Post: 07-30-2007, 08:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks