package logics;
public class reverseUsingRecurtion {
public static void main(String []a)
{
String name="shahi kumar";
System.out.print(reverse(name));
}
public static String reverse(String data)
{
if(data.length()==1)
return data;
String rev="";
rev=rev+data.charAt(data.length()-1)+reverse(data.substring(0,data.length()-1));
return rev;
}
}//class
output
---------------
ramuk ihahs
public class reverseUsingRecurtion {
public static void main(String []a)
{
String name="shahi kumar";
System.out.print(reverse(name));
}
public static String reverse(String data)
{
if(data.length()==1)
return data;
String rev="";
rev=rev+data.charAt(data.length()-1)+reverse(data.substring(0,data.length()-1));
return rev;
}
}//class
output
---------------
ramuk ihahs
Không có nhận xét nào:
Đăng nhận xét