Reverse each word of a sentence
import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
public class Reverse_words_sentence {
public static void main(String[] args)
{
String sStr=JOptionPane.showInputDialog("Enter a string");
String[] sArr=StringUtils.split(sStr, " ");
String sRes;
for (int i=0 ;i<=sArr.length-1;i++)
{
sArr[i]=StringUtils.reverse(sArr[i]);
}
sRes=StringUtils.join(sArr, " ");
System.out.print(sRes);
}
{
String sStr=JOptionPane.showInputDialog("Enter a string");
String[] sArr=StringUtils.split(sStr, " ");
String sRes;
for (int i=0 ;i<=sArr.length-1;i++)
{
sArr[i]=StringUtils.reverse(sArr[i]);
}
sRes=StringUtils.join(sArr, " ");
System.out.print(sRes);
}
}
No comments:
Post a Comment