Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
Practice Tech Mahindra Essay Topics

Program Discussion :: Strings

Home > Programs > Strings

22 / 59

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: