
Write a program to print "Ranjan pintu am i". the given string is i am pintu ranjan. here there is a condition, we can't use split() method, using loop only.

import java.util.*;
public class ReverseString{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
StringBuffer buffer=new StringBuffer();
System.out.println("Enter string: ");
String str=input.nextLine();
Stack stack=new Stack();
StringTokenizer stk=new StringTokenizer(str," ");
while(stk.hasMoreTokens()){
stack.push(stk.nextElement());
}
System.out.print("Reverse word string: ");
while(!stack.empty())
{
System.out.print(stack.pop());
System.out.print(" ");
}
System.out.println(" ");
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.