Computer Science, asked by anmolanand2k15, 20 hours ago

WAP in JAVA to accept a sentence and replace the first letter of each word with ‘X’. Finally display the new sentence.

Answers

Answered by samarthkrv
3

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 sentence:");

 String str = sc.nextLine();

 char[] arr = str.toCharArray();

 arr[0] = 'X';

 int i = 0;

     while(i < arr.length){

         if(arr[i] == ' '){

              arr[i+1] = 'X';

         }

         i++;

     }

 String x = "";

     for (char c : arr){

         x = x + c;

     }

     System.out.println(x);

}

}

Explanation:

Similar questions