Problem:
Print a string using recursion in Java.
Output:
Not Applicable.
Solution:
01 | public static void printchars(String str) |
02 | { |
03 | if (str == null || str.equals( "" )) |
04 | { |
05 | return ; |
06 | } |
07 | |
08 | else |
09 | { |
10 | System.out.print(str.charAt( 0 )); |
11 | printchars(str.substring( 1 )); |
12 | } |
13 | } |
No comments :
Post a Comment