• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can anybody solve the problem without using loop

 
Rahul Shivsharan
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given two strings, append them together (known as "concatenation") and return the result. However, if the concatenation creates a double-char, then omit one of the chars, so "abc" and "cat" yields "abcat".

conCat("abc", "cat") → "abcat"
conCat("dog", "cat") → "dogcat"
conCat("abc", "") → "abc"
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We try not to give out ready made answers (that's not what this site is for ). What have you tried so far? What do you reckon you need to do?
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any algorithm that uses a loop can be rewritten without the loop using recursion.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You won't even need a loop or recursion. Check out String's length(), charAt(int) and substring(...) methods.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul has posted a solution here.
 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to remember seeing that example on a website I had been using to practice different java problems. If that is where you got this problem can you plase give me the url, I cant seem to remember where it was
 
Rahul Shivsharan
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Kohanek wrote:I seem to remember seeing that example on a website I had been using to practice different java problems. If that is where you got this problem can you plase give me the url, I cant seem to remember where it was......... , this is the solution , but i want to improvise it further, can you just give me a hint how


 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic