Saturday, 23 July 2016

Q.2 Reverse the given Stirng by word
import java.util.Scanner;

public class ReverseByWord {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter a Sentence");
String s=sc.nextLine();
System.out.println(s);
String s1="",rev="";
for(int i=0;i<s.length();i++){
if(s.charAt(i)!=' '){
s1=s.charAt(i)+s1;
}
else{
rev=rev+" "+s1;
s1="";
}
}rev=rev+" "+s1;
System.out.println(rev);
}

}

No comments:

Post a Comment

Featured post

All Logical Questions are Answered JumpInToIt