0
Please tell me the output of following code and tell me the error in this code.
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String text = scanner.nextLine(); String rev = ""; int len=text.length(); for(int i=len-1;i>=0;i--){ rev = rev+text.CharAt(i); } System.out.println(rev); } }
6 Respuestas
+ 1
The loop should continue while <i> was greater than or equal to zero. That is ... `i >= 0` , not `i <= 0`
for( int i = len -1; i >= 0; i--)
A typo in writing method name, it's charAt() , not CharAt()
rev = rev + text.charAt( i );
+ 1
Ya thanks but it is showing that cannot find symbol at <.CharAt>
+ 1
Thanks it works
0
Because it should be `charAt` rather than `CharAt`
Notice the first letter 'c' and 'C'
Java is case sensitive language, a different letter case matters.
0
Iwas stucked only because of this 'c'
0
LOL it happens, take it easy ...