package com.dashzin.prog;
import java.util.Scanner;
public class String11 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter your string");
String st=sc.nextLine();
String[] words = st.split(" ");
String reversedString = "";
for (int i = 0; i < words.length; i++)
{
String word = words[i];
String reverseWord = "";
for (int j = word.length()-1; j >= 0; j--)
{
/* The charAt() function returns the character
* at the given position in a string
*/
reverseWord = reverseWord + word.charAt(j);
}
reversedString = reversedString + reverseWord + " ";
}
System.out.println(st);
System.out.println(reversedString);
}
}
Output :
welcome to dashzinemoclew ot nizhsad
0 comments:
Post a Comment