Computer Science, asked by masthanshaikreb, 3 months ago

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.



Sample Input:

hello there



Sample Output:

ereht olleh​

Answers

Answered by sohamshirke007
7

Answer:

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

       

       String rev = "";

       for (char i: arr)

           rev = i + rev;  

       System.out.println(rev);

   }

}

Answered by mdhananjaya04
0

Answer:

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 result = arr.length;

 for( int i = 0; i < arr.length; i++){

  result -= 1;

  System.out.print(arr[result]);

 }

}

}

Explanation:

Similar questions