Java String Char Count countChar(String s, char c)

Here you can find the source of countChar(String s, char c)

Description

count Char

License

Open Source License

Declaration

public static int countChar(String s, char c) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014, Superloup10//from   w ww  .  java  2 s . c om
 *
 * This work is made available under the terms of the GNU GENERAL PUBLIC LICENSE:
 * http://www.gnu.org/licenses/gpl-3.0.en.html
 * Contact the author for use the sources
 *
 * Cette ?uvre est mise ? disposition selon les termes de la GNU GENERAL PUBLIC LICENSE:
 * http://www.gnu.org/licenses/gpl-3.0.fr.html
 * Contacter l'auteur pour utiliser les sources
 ******************************************************************************/

public class Main {
    public static int countChar(String s, char c) {
        System.out.println("C:" + c);
        int n = 0;
        for (char c1 : s.toCharArray()) {
            System.out.println("C1:" + c1);
            if (c1 == c) {
                n++;
                System.out.println("Ntres" + n);
            }
            System.out.println("Nbis:" + n);
        }
        return n;
    }
}

Related

  1. countChar(String s, char c)
  2. countChar(String s, char c)
  3. countChar(String sql, int end)
  4. countChar(String src, char c)
  5. countChar(String str, char c)
  6. countChar(String str, char c)