Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners what is the correct format of charAt() function?

Have Programming Question? Ask it here!
 
 
 


chitta.manonmani
what is the correct format of charAt() function?
1 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


    class prog{
      String a[]={"manu is a good girl"};
     int count=0;
    public void cal1(String search){
             int i;
        // String s=search;
         for(i=0;i<=14;i++){
         if(charAt(i)=='a'){
           count++;         }
           }
           System.out.println("count:"+count);
       }
     }
     class p3{
     public static void main(String ar[]){
       prog obj=new prog();
       obj.cal1(ar[0]);
       }
       }

in the above program the following errors are coming: p3.java:8:cannot find symbol symbol:method charAt(int) location:class prog if(charAt(i)=='a'){

But the syntax of the charat()function is correct in the code.


Advertisement
View Answers

January 4, 2011 at 2:13 PM


Hi Friend,

Try the following code:

class prog{

    int count=0; 
    public void cal1(String search){
        int i; 
        String s=search;
        for(i=0;i<s.length();i++){
        if(s.charAt(i)=='a'){
        count++;
        } 
        }
        System.out.println("count:"+count);
        }
    }
class p3{
        public static void main(String ar[]){
        prog obj=new prog();
        obj.cal1(ar[0]);
        }
}

Thanks



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com