Cross posted here
Welcome to the forum! Please read this topic
to learn how to post code in code or highlight tags and other useful info for new members.
Please post your code correctly. Once you see how at the link I've provided, you can edit your post with the tags of your choice.
Also, add details about your question. What's wrong with the method you've written? If you're getting errors, post those. If you're getting incorrect results, show a sample run and describe what's wrong with it and ask how to improve it.