The code defines a method to count the number of occurrences of a character in a string. It then prompts the user to enter a string, loops through each character, counts the occurrences of that character, and prints the results.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
17 views
Test String
The code defines a method to count the number of occurrences of a character in a string. It then prompts the user to enter a string, loops through each character, counts the occurrences of that character, and prints the results.
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
import java.util.
Scanner;
public class TestString {
public static int Find(String string, char key) { int count = 0; for (int i = 0; i < string.length(); i++) { if (string.charAt(i) == key) { count++; } } return count; }