Computer Science, asked by arya2005singh, 3 days ago

write a Java program
Accept a sentence from user and print all the words which starting and ending letter same. (6) Input :- GOING TO AGRA Output :- AGRA

Answers

Answered by samarthkrv
0

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 Scanner sc = new Scanner(System.in);

 System.out.print("Enter a string:");

 String s = sc.nextLine();

 System.out.println("Words which start and end with same letter is-");

     for (String str : s.split(" ")){

         if(str.charAt(0) == str.charAt(str.length()-1) && str.length()!=1){

             System.out.println(str);

         }

     }

}

}

Explanation:

Mark as brainliest pls

Similar questions