public class StringBackward { public static void reverseString(String word, int size) { if(size==0) { return; } else { System.out.print(word.charAt(size-1)); reverseString(word, size-1); } } } //main class import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); String word; System.out.print("Enter a word: "); word = input.next(); StringBackward access = new StringBackward(); System.out.print("The reverse word is: "); access.reverseString(word, word.length()); System.out.println(); } }
0 comments:
Post a Comment