Last active
April 3, 2017 12:54
-
-
Save gitaficionado/21e676354e289913cca6567bda2c876a to your computer and use it in GitHub Desktop.
(Occurrences of a specified character) Write a method that finds the number of occurrences of a specified character in a string using the following header: public static int count(String str, char a)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class DisplayChar { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.print("Enter a string: "); | |
______________ = input.nextLine(); | |
System.out.print("Enter a character: "); | |
____________ = input.nextLine().charAt(0); | |
int times = count(__ , ___); | |
System.out.println(ch + " _______________ " + times + (________ > 1 ? " times " : " time ") + "in " + __); | |
} | |
public static int count(String str, char a) { | |
int result = 0; | |
if (_________________() > 0) | |
result = _______________(str.substring(1), a) + | |
((str.charAt(0) == __) ? 1 : 0); | |
return ________; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment