java - no error raised by compiler but not getting the correct answer in character occurrence program -


string s1=t1.gettext(); char ch=t2.gettext().charat(0); int a=0;   int i=0;  for(i=0;i<s1.length();i++) { if(s1.charat(i)==ch)     a++; }t3.settext(""+a); 

this code t1,t2,t2 textfields. compiler doesn't raises error repeatedly getting 1 result no matter whatever character @ whatever place use. please help!!!

string s1="hello world"; char ch= 'o'; int a=0;   for(int i=0;i<s1.length();i++){     if(s1.charat(i)==ch){         a++;     } }  system.out.println(""+a); 

works perfectly. however, if not provide character exists in s1you not result.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -