How can you reverse a string?

Answer Posted / milind s

Most of time in interview asked without using Build Function**

public String reverse(String arg)
{
String tmp = null;
if (arg.length() == 1)
{
return arg;
}
else
{
String lastChar = arg.substring(arg.length() - 1,
arg.length());
String remainingString = arg.substring(0,
arg.length() - 1);
tmp = lastChar + reverse(remainingString);
return tmp;
}
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain about exception propagation?

583


When the constructor of a class is invoked?

587


What is a singleton in genetics?

560


How will you add panel to a frame?

642


Explain thread life cycle in java?

587






How is the marker interface used in Java?

606


What are multiple inheritances?

579


What is method overriding in java ?

653


Can you instantiate the math class in Java?

605


What are the files generated after using IDL to java compiler?

582


What is string english?

537


Can a method be overloaded based on different return type but same argument type?

546


Is binary a low level language?

499


What is java jit compilers?

559


If we allocate the memory using 'new' & de-allocated using 'free' then what will happen?

590