import s.length(); i++) { chr[i] = s.charAt(i); if

import java.util.Scanner;import java.io.*;import java.lang.*;import java.util.stream.IntStream;import java.util.regex.Pattern;public class DesaiDhruviA3 { static int word_count(String s) { // counting words in the string int count = 0; char chr = new chars.length(); for (int i = 0; i < s.length(); i++) { chri = s.charAt(i); if (((i > 0) && (chri != ‘ ‘) && (chri – 1 == ‘ ‘)) || ((chr0 != ‘ ‘) && (i == 0))) count++; } return count; } static String revStr(String rs) { //reversing words in the string Pattern pattern = Pattern.compile(“\s”); String temp = pattern.split(rs); String reverseString= “”; for (int i = 0; i < temp.length; i++) { if (i == temp.length - 1) reverseString = tempi + reverseString; else reverseString = " " + tempi + reverseString; } return reverseString; } public static void main (Stringargs) { String str1="",str2="",str3="",findStr=""; str1 ="When Mr. and Mrs. Dursley woke up on the dull, gray Tuesday our story starts, there was nothing about the cloudy sky outside to suggest that strange and mysterious things would soon be happening all over the country. Mr. Dursley hummed as he picked out his most boring tie for work, and Mrs. Dursley gossiped away happily as she wrestled a screaming Dudley into his high chair "; System.out.println("Total number of words in the string: "+ word_count(str1)); findStr = "Mr."; // replacing Mr. with Respected Sir int lastIndex = 0,count = 0; while(lastIndex != -1){ lastIndex = str1.indexOf(findStr,lastIndex); if(lastIndex != -1){ count ++; lastIndex += findStr.length(); } } System.out.println(" Number of Occurrences of "Mr.": "+ count); str2 = str1.replace("Mr.", "Respected Sir"); System.out.println(" Replacing 'Mr.' with 'Respected Sir':"); System.out.println(str2); System.out.println(" Total number of words in the string: "+ word_count(str2)); Scanner lineScan = new Scanner(str2);// First letter capital while(lineScan.hasNext()) { String word = lineScan.next(); str3 += Character.toUpperCase(word.charAt(0)) + word.substring(1) + " "; } System.out.println(" First letter Capital paragraph:"); System.out.println(str3.trim()); System.out.println(" Reverse of the string is: "); System.out.println(revStr(str3)); }}//Refrences : https://www.geeksforgeeks.org/reverse-words-given-string-java///https://www.w3resource.com/java-exercises/basic/java-basic-exercise-58.php