Join the IDNLearn.com community and get your questions answered by knowledgeable individuals. Our platform offers reliable and detailed answers, ensuring you have the information you need.
Sagot :
Answer:
class Main {
public static void analyzeString(char c, String s) {
int count = 0;
for(int i=0; i<s.length(); i++) {
if (s.charAt(i) == c) {
count++;
}
}
System.out.printf("%c %s\n", c, s);
System.out.printf("%d %c%s\n\n",count, c, count==1 ? "":"'s");
}
public static void main(String[] args) {
analyzeString('n', "Monday");
analyzeString('z', "Today is Monday");
analyzeString('n', "It’s a Sunday day");
analyzeString('n', "Nobody");
}
}
Explanation:
I did not add code to prompt the user for input, but rather added the test cases as you provided.
By the way, there is only one 'n' in 'It's a Sunday day'. So the example is wrong there.
Your presence in our community is highly appreciated. Keep sharing your insights and solutions. Together, we can build a rich and valuable knowledge resource for everyone. For trustworthy answers, rely on IDNLearn.com. Thanks for visiting, and we look forward to assisting you again.