aspose file tools*
The moose likes Java in General and the fly likes Can anybody  solve the problem without using loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Can anybody  solve the problem without using loop" Watch "Can anybody  solve the problem without using loop" New topic
Author

Can anybody solve the problem without using loop

Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
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

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Any algorithm that uses a loop can be rewritten without the loop using recursion.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

You won't even need a loop or recursion. Check out String's length(), charAt(int) and substring(...) methods.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

Rahul has posted a solution here.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

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


True wisdom is in knowing you know nothing - Socrates
Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
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


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can anybody solve the problem without using loop
 
Similar Threads
Displaying values of variables of an object
Tech Word Game
apply query after concate two column
Can The Solution of the problem which i have solved can be further more improvised
String literal objects in String pool