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
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