I need to reverse Hello. using recursion so that the end result does not have a .
My current method is:
public void foo(){
Scanner scan = new Scanner(system.in);
char c = scan.nextChar();
if (c!='.')
foo();
System.out.print(c);
}
This seems to output the reverse, however it still has the .. Can someone point me in the right direction to get rid of the period?
Use
'.'instead of"."since you are comparing achar, not aString:Also note that if it were a
String, you’d need to useequalsto do the comparison.==or!=is used to compare primitive types, such aschar.