Reverse of a array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Reverse of a array

Pls find the error

3rd Mar 2021, 7:14 PM
Rachita Bhasin
4 Answers
+ 3
When iterating backwards the first index should be arr.length -1, not arr.length.
3rd Mar 2021, 8:30 PM
Sonic
Sonic - avatar
+ 3
Use i>=0 rather than i>0 when iterating backwards.
3rd Mar 2021, 8:31 PM
Sonic
Sonic - avatar
+ 2
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String text = scanner.nextLine(); char[] arr = text.toCharArray(); char[] c; //your code goes here for(int i=arr.length;i>0;i--) c[]=arr[i]; for(int i=0;i<arr.length;i++) System.out.print(c[]); } }
3rd Mar 2021, 7:14 PM
Rachita Bhasin
+ 2
Rwemember to smwile :) Smwiling is evwey thing in da world
3rd Mar 2021, 7:16 PM
BUZZSAW
BUZZSAW - avatar