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); } }

5th Jun 2022, 3:08 AM
Krishna Varshney
Krishna Varshney - avatar
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 );
5th Jun 2022, 3:25 AM
Ipang
+ 1
Ya thanks but it is showing that cannot find symbol at <.CharAt>
5th Jun 2022, 3:38 AM
Krishna Varshney
Krishna Varshney - avatar
+ 1
Thanks it works
5th Jun 2022, 3:41 AM
Krishna Varshney
Krishna Varshney - avatar
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.
5th Jun 2022, 3:40 AM
Ipang
0
Iwas stucked only because of this 'c'
5th Jun 2022, 3:42 AM
Krishna Varshney
Krishna Varshney - avatar
0
LOL it happens, take it easy ...
5th Jun 2022, 3:43 AM
Ipang