Computer Science, asked by Sd12365, 10 months ago

Write a program in java to accept a sentence and remove the first and last alphabet from each word.

Input: We are from India
Output: We r ro ndi

please solve this program.....​

Answers

Answered by pavithranatarajan855
1

import java.util.*;  

 

class Remo {  

   static String FirstAndLast(String str)  

   {  

 

       // Split the String based on the space  

       String[] arrOfStr = str.split(" ");  

 

       // String to store the resultant String  

       String res = "";  

 

       // Traverse the words and  

       // remove the first and last letter  

       for (String a : arrOfStr) {  

           res += a.substring(1, a.length() - 1) + " ";  

       }  

 

       return res;  

   }  

 

   // Driver code  

   public static void main(String args[])  

   {  

        Scanner s=new Scanner(System.in);

       String str =s.nextLine();

       System.out.println(FirstAndLast(str));  

   }  

}

Explanation:

Similar questions