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 s1
you not result.
Comments
Post a Comment