Question
The following code has numerous errors that need to be fixed. import java.util.Scanner; public class LabProgram { public static int calcNumCharacters(String userString, char userChar) {
The following code has numerous errors that need to be fixed.
import java.util.Scanner; public class LabProgram { public static int calcNumCharacters(String userString, char userChar) { int i; int numChars; i = ; numChars = ; while (i < userString.length() { if (userString.charAt(i) == userChar) { ++numchars; ++i; } retrn numChars; } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); inputChar; inputString; numChars; inputChar = scnr.next().charAt(0); inputString = scnr.nextLine(); numChars = calcnumCharacters(inputString, inputChar); System.out.print(numChars); System.out.print(" " + inputChar); if (numChars != 1) { System.out.print("'s"); } System.out.println();
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started