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
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
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
India Languages,
1 month ago
Science,
1 month ago
English,
1 month ago
Physics,
3 months ago
Social Sciences,
3 months ago
History,
9 months ago