Untitled
package javaapplication8; import java.util.Scanner; public class JavaApplication8 { public static void main(String[] args) { String name; Scanner sobj=new Scanner(System.in); System.out.println("enter the string:"); name=sobj.next(); char c; System.out.println("enter the character to be counted:"); c=sobj.next().charAt(0); int x=0; for(int i=0;i<name.length();i++) { if(c==name.charAt(i)) { x++; } } System.out.println("the count of each character in the given string is"+x); } }
Leave a Comment