Write a program which takes a String input, and then prints the number of times the string "sh" appears in the String (s and h can be any case). Hint - remember there are String methods which return a copy of the String it is called on with all letter characters changed to the same case.

Respuesta :

Answer:

str = input("Input: ")

str = str.lower()

counts = str.count("sh")

print(counts)

Explanation:

I answered the question in Python programming language.

[This line prompts user for input]

str = input("Input: ")

[This line converts user input to lower case]

str = str.lower()

[This counts the occurrence of "sh" in the input string]

counts = str.count("sh")

[This prints the number of occurrence of "sh" in the user input]

print(counts)

Answer:

Scanner scan=new Scanner(System.in);

System.out.println("Input String:");

String str = scan.nextLine();

int count = 0;

str=str.toLowerCase();

for (int i = 0; i < str.length()-1; i++)

{

 if (str.substring(i, i + 2).equals("sh"))

 {

   count++;

 }

}

System.out.println("Contains \"sh\" " + count + " times.");

}

}

Explanation:

This is what I was able to get for Java.