Write a java program which accepts a string and a characters to be search from the user the program should display the totalno of character in string.||EasyCoding45

 In this tutorial ,we are going to learn how we can *Write a java program which accepts a string and a characters to be search from the user and also count and display the length of the String*.


Program ::--

import java.util.*;

class search

{

public static void main(String a[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter String :");

String str=sc.next();

System.out.println("Enter Character :");

String ch=sc.next();

int len=str.length();

char c=ch.charAt(0);

char search[]=new char[len];

int cnt=0;

for(int i=0;i<len;i++)

{

search[i]=str.charAt(i);

}

for(int i=0;i<len;i++)

{

if(search[i]==c)

System.out.println("Character Found :");

else

cnt++;

}

if(cnt==len)

System.out.println("Character not Found :");

System.out.println("No of characters in String is :"+len);

}

}


Output ::--


                    Thank You💚

Comments