JAVA Programs


//WAP TO REVERSE A GIVEN SENTENSE


import java.util.*;
public class ReverseSentense
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s;
System.out.println("Enter a sentense:");
s=sc.nextLine();
String temp[];
temp=s.split(" ");
for(int i=temp.length-1;i>=0;i--)
System.out.print(temp[i]+" ");
}
}

output:-
let the input be:
hello my name is rishabh
then the output will be:
rishabh is name my hello

No comments:

Post a Comment