Answer:
import java.util.Scanner;
public class CountT {
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
System.out.println("Enter a word");
String word = in.nextLine();
//convert to all lower case
String str = word.toLowerCase();
int tcount = 0;
for(int i= 0; i<str.length(); i++){
if(str.charAt(i)=='t'){
tcount++;
}
}
System.out.println("Total number of ts: "+tcount);
}
}
Explanation:s
- Import Scanner class
- Prompt user for input
- Store in a variable
- Convert user's input into all lower cases
- Create a variable tcount and initilize to zero
- Using a for loop, iterate through the entire length of the string and increment tcount by 1 each time the character t is found
- Output tcount