menu search
brightness_auto
more_vert

Can you help me? Java Code

Write a program to take a string as input and output its reverse.
The given code takes a string as input and converts it into a char array, which contains letters of the string as its elements.

thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike

1 Answer

more_vert

Try

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();
       
        //your code goes here
        int n=arr.length;
        String str="";
       for(int i=n-1 ; i>-1 ; i--){
           str=str+arr[i];
       }        
       System.out.println(str);
    }
}
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
eForumAfrica, where you can ask questions and receive answers from other members of the community. Find the answer to your question, help others by answering their questions.
...