Skip to content

Instantly share code, notes, and snippets.

@mariiaKolokolova
Created May 3, 2020 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariiaKolokolova/cdd164e9689dcc2f24ca4a5b696132b7 to your computer and use it in GitHub Desktop.
Save mariiaKolokolova/cdd164e9689dcc2f24ca4a5b696132b7 to your computer and use it in GitHub Desktop.
package maricka.kolokolova;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str;
System.out.println("Please enter a string to count 'b':");
Scanner sc = new Scanner(System.in);
str = sc.nextLine();
char[] text = str.toCharArray();
int cn = 0;
for (int i = 0; i < text.length; i++) {
if (text[i] == 'b') {
cn++;
}
}
System.out.println("You have " + cn + " 'b's in your string ");
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment