Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain the chemical properties of acids with examples.

Answered: 1 week ago

Question

Write the properties of Group theory.

Answered: 1 week ago

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago

Question

5. Tell how job experiences can be used for skill development.

Answered: 1 week ago