Saturday, May 22, 2010

Plzz....can u tell me what's wrong in this program.....there is error on 15,17...!!?

import java.io.*;


class overload


{


public int add(int x,int y)


{


return(x+y);


}


public int add(int a,int b,int c)


{


return(a+b+c);


}


public void disp()


{


System.out.println("addition is ");


System.out.println(add(l,m));


System.out.println("addition of a,b,c is ");


System.out.println(add(l,m,n));


}


}


class display


{


public static void main(String s[])


{


DataInputStream in = new DataInputStream(System.in);


int l,m,n;


try


{


System.out.println("enter three no.s ");


l=Integer.parseInt(in.readLine());


m=Integer.parseInt(in.readLine());


n=Integer.parseInt(in.readLine());


}


catch(Exception e){}


overload o=new overload();





o.disp();








}


}

Plzz....can u tell me what's wrong in this program.....there is error on 15,17...!!?
Love to see a Java programmer in Yahoo. Answers and pleasure to help you.





In line 15 :System.out.println(add(l,m)); the compiler don't know what are "l" and "m"


Also in 17: System.out.println(add(l,m,n))...it doesn't know l,m and n. Use ";" instead "..."





Instead of public void disp() use public void disp(int l,int m, int n)


Then in line 36: use o.disp(l,m,n);





The reason for your error is in method disp() it doesn't know anything about l,m and n.
Reply:for clarity:





oh... don't use datainputstream... learn Scanner. Sooo much better than any other input method.





for fixing:





make it "public class xxx"


int l,m,n; should be instantiated inside class header, not inside the main.


Since you are using an object to call disp(), have object o contain the values l, m, n by using a constructor.


No comments:

Post a Comment