+ 1
Reverse a string words without using function
Ex Input:- hello world Output:- world hello
4 Answers
+ 2
It's easy if you master indexing skills........like reverse indexing and use of loops also
0
How can I make this print
0
1) identify words or, in other words, index of start and end of current word in string
2) for any word, swap characters using a pivot index betwen start and end word
Anyway, its better post your try so we can help you more
- 1
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 reverse="";
for(int i=arr.length-1; i>=0; i--){
reverse=reverse+arr[i];}
System.out.print(reverse);
}
}