Idea: Recursion. Start from 0, print, add 1 then recursively next until 255
Time: O(1) Space: O(1)
Code:
public class printAllASIC {
public printAllASIC()
{
printASIC(0);
}
public void printASIC(int charNum)
{
if(charNum<255)
{
char toPrint=(char)charNum;
System.out.println(toPrint);
printASIC(charNum+1);
}
}
}
No comments:
Post a Comment