Answer to Question #3808 in AJAX | JavaScript | HTML | PHP for MohammadAnbar

Question #3808
Write a method in Java which is passed a character (recursion) that prints all characters between ‘a’ and that character.

For example user entered: f ......... then the output should be: abcdef
1
Expert's answer
2011-08-03T15:19:46-0400
import java.io.IOException;public class recurs {

public static void main(String[] args){
char c = 'z';
System.out.print("Enter character from a to z: ");
try {
c = (char)System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
rec_print('a',c);
}
static void rec_print(char from, char to)
{
System.out.print(from);
from++;
if (from <= to) rec_print(from,to);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS