0

I have to write a function that prepends if boolean is true or append if boolean is false a string to an array. I'm not exactly sure what this means? Do I just add a string to the first element of the array if I'm prepending or add a string to the last element of the array if I'm appending? Or what?

2
  • 1
    Question isn't that clear but since this is homework you should ask some doubts to your proff. or teacher and get it clarified. Commented Oct 9, 2010 at 21:16
  • It sounds to me like you are supposed to write a function which takes a boolean flag. However, the assignment itself is ambiguous. It hasn't clearly described what you're supposed to append/prepend the string to. Commented Oct 9, 2010 at 21:20

3 Answers 3

2

That could either mean append the String to the last String of the array or add a new element in your array.

But I really think that's about adding elements in an array (either at the start or at the end of the array).

Sign up to request clarification or add additional context in comments.

Comments

1

Well the question states that append string to array depending on Boolean. Convert string to array and add each character to the Array. Appending to easy and for pre-pending you need to write a array routine to move the array elements to provide space for pre-pending string characters.

Comments

0

You could user StringBuilder instead of using array and just append ur string at the first of the stringBulder . E.g: StringBuilder str = new StringBuilder(); str.append("everyBody"); str.insert(0, "hello "); System.out.println(str.toString());

1 Comment

As it's an assignment I don't think he can bend the rules ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.