Ads Top

Program to find out the Repetition of character in a String

 Repetition of character in a String

import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the String : ");
String value = sc.nextLine();
//System.out.println();
System.out.print("Enter the Charcter : ");
String ch = String.valueOf((sc.next().charAt(0)));
int count=0;
for(int i=0;i<value.length();i++)
{
if((String.valueOf(value.charAt(i))).equalsIgnoreCase(ch))
{
count++;
}
}
System.out.println("The character : "+ ch +" is present "+count+" times");
}
}

Output :
Enter the String : hello
Enter the Charcter : l
The character : l is present 2 times
 


No comments:

Powered by Blogger.