Prev: Problem tracking down an error
Next: add authorization header (user/password) before sendRedirect
From: focode on 3 Dec 2009 10:29 Consider the following function : String[] concat(String[] Final, String[] Fresh) { String[] C= new String [A.length+B.length]; System.arraycopy(A, 0, C, 0, A.length); System.arraycopy(B, 0, C, A.length, B.length); return C; } this is the fuction to concatinate two strings in java suppose: String[] A = {"a","b","c"}; and String[] B = {"d","e","f"}; calling fuction concat like this : String[]F=concat(a,b) System.out.println(f[5]) // this will produce f , correct ! i have to do this proccess recursively , in the following way /////////////////////////////////////////////////////////////////// String[] UID_of_msg; String[] uid_final; int i = 10; void recurse() { i = i+10; UID_of_msg = // always freash value , index value of "UID_of_msg" range from 0 to 11 uid_final = concat(uid_final,UID_of_msg);// this should go on concatinating "UID_of_msg" in to "uid_final" in ever execution of function "recurse" // so that when value of i is 30 (i.e 3rd execution) , then uid_final [30] should print the last value , but in my case it is printing error "index out of bound exception" // and when i print the length of uid_final i.e executing "uid_final.length" , it prints 12 i.e only value of one execution of function "recurse" is stored in "uid_final" recurse(); } i would request to concatinate the two string arrays , in a way to solve the requirment of the situation . thanks and regards Arunesh
From: markspace on 3 Dec 2009 10:37 focode wrote: > i have to do this proccess recursively , in the following way > i would request to concatinate the two string arrays , Why use recursion? Is this a school assignment? Because recursion is probably the worst choice that could be made for concatenation. That said, I'd need a example program from you that shows the error before I could guess what is going on.
From: Lew on 3 Dec 2009 10:58 focode wrote: > Consider the following function : > > String[] concat(String[] Final, String[] Fresh) Variable names should start with a lower-case letter by convention. Otherwise they look like type names and confuse the reader. > { For crying out loud, focode, you've been posting to this enwsgroup long enough to know not to use such ridiculous indentation. No more than four spaces per level please. (No TABs.) If you want people to help you, you need to make the code readable. > String[] C= new String > [A.length+B.length]; And accurate. What are 'A' and 'B'? > System.arraycopy(A, 0, C, > 0, A.length); > System.arraycopy(B, 0, C, > A.length, B.length); > return C; > > } > > this is the fuction to concatinate two strings in java [sic] > > suppose: > > String[] A = {"a","b","c"}; > and > String[] B = {"d","e","f"}; > > calling fuction concat like this : > > String[]F=concat(a,b) > System.out.println(f[5]) // this will produce f , correct ! > > i have to do this proccess recursively , in the following way Why do you "have to" do it recursively? As markspace pointed out, this is not the best way. > String[] UID_of_msg; Not only should (non-constant) variable names start with a lower-case letter, they should not contain underscores. Use camel case, e.g., 'uidOfMsg'. > String[] uid_final; > int i = 10; > void recurse() > { > i = i+10; And now you abandon indentation altogether! I'm not even going to read the rest. -- Lew
From: rossum on 3 Dec 2009 11:47 On Thu, 3 Dec 2009 07:29:26 -0800 (PST), focode <programarunesh(a)gmail.com> wrote: >i have to do this proccess recursively , in the following way Start with a collection of strings. If the collection contains only one string then return that string and terminate. If the collection contains more than one string then concatenate the first two strings to produce a collection with one less string and repeat. This is a standard format for a simple recursive process. Each iteration reduces some value and when the value reaches the desired limit the process exits. rossum
|
Pages: 1 Prev: Problem tracking down an error Next: add authorization header (user/password) before sendRedirect |