Reverse character using void method
I ^:)^need help to write a parameterless, void and recursive method used to reverse a string of character. Can anybody help me with the last part?
This is the code I been able to write so far :
Code Java:
import java.util.*;
public class Labex78
{
public static String put = put;
static boolean check= true;
public static void main(String[] args)
{
reverse();
}
public static void reverse()
{
Scanner kbd= new Scanner(System.in);
if(check==true){
System.out.println("Enter 5 characters");
put = kbd.nextLine();
check= false;}
int len = put.length();
if(len<=1)
{
System.out.print(put);
}
else
{
String rev ="";
rev += put.charAt(put.length()-1);
put= put.substring(0,put.length()-1);
reverse();
System.out.println(" Read backwards, character becomes "+ rev);
}
}
}
Re: Reverse character using void method
Re: Reverse character using void method
doesn't work . that ELSE part is not reversing the string. and I was wondering how I can use a void , parameterless function that is also recursive without keeping ro prompt the user to enter a string of characters. Basically how do use a string input by a user in such function??