[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Strings

Home > Programs > Strings

275 / 60

Write a program enter the sentence then print it in reverse order.

Answer:

import java.io.*;
public class ReverseWord 
{
 public static void main(String[] args) 
 { 
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the string"); 
  String str=br.readLine();
  String a[]=str.split(" ");
  for(int i=a.length-1; i>=0; i--)
  {
   System.out.print (a[i]+" ");
  }
 }

Asked In :: IBM

Post Your Answer Here:

Language:

Post Your Reply Here: