Ask Experts Questions for FREE Help !
Ask
    junaidahmd's Avatar
    junaidahmd Posts: 1, Reputation: 1
    New Member
     
    #1

    Mar 3, 2013, 05:31 AM
    error
    what's the error in the prog...




    import java.util.Scanner;
    public class g {


    public static void main(String[] args) {
    Scanner s=new Scanner(System.in);
    int d,x,y;

    System.out.println("Enter the first number");
    x=s.nextInt();
    System.out.println("Enter the second number");
    y=s.nextInt();
    public void add(){
    d= x+y;
    System.out.println(d);
    }
    public void sub(){
    d= x-y;
    System.out.println(d);
    }

    int a;
    System.out.println("Enter ur choice");
    a=s.nextInt();
    switch(a)
    { case 1:add();
    break;
    case 2:sub();
    break;
    default :System.out.println("invalid choice");
    break;
    }
    }
    }
    rameshspry's Avatar
    rameshspry Posts: 4, Reputation: 1
    New Member
     
    #2

    Jul 4, 2013, 10:51 PM
    you have to write the add and sub methods out side of the main method

    Like this...

    import java.util.Scanner;
    public class g {


    public static void main(String[] args) {
    Scanner s=new Scanner(System.in);
    int d,x,y;

    System.out.println("Enter the first number");
    x=s.nextInt();
    System.out.println("Enter the second number");
    y=s.nextInt();


    int a;
    System.out.println("Enter ur choice");
    a=s.nextInt();
    switch(a)
    {
    case 1:add(x,y);
    break;
    case 2:sub(x,y);
    break;
    default :System.out.println("invalid choice");
    }
    }
    public static void add(int x, int y){
    int d= x+y;
    System.out.println(d);
    }
    public static void sub(int x, int y){
    int d= x-y;
    System.out.println(d);
    }

    }

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

IE printing error: res://ieframe.dll/preview.dlg error [ 15 Answers ]

I have seen about a dozen posts on different Web sites regarding this error. The most common fixes are related to an individual work station. We are experiencing this problem with our Web site and everyone accessing it is unable to print pages that are within frames. I tried the fixes on my...

Oracle Error 12560:tns Protocol Adapter Error [ 3 Answers ]

Hi, Whenever I try to log in using SCOTT/TIGER userid, I get the error "ORA ERROR 12560:TNS PROTOCOL ADAPTER ERROR". I tried starting the listener from administration-> services, but still the problem persists. Can you please suggest a solution?

Socket Error: 11001, Error Number: 0x800CCC0D [ 2 Answers ]

How can I solve Socket Error: 11001, Error Number: 0x800CCC0D ?

Secure(SSL): No, Socket Error: 11001, Error Number: 0x800CCC0D [ 1 Answers ]

How can I send instant mail into my inbox? When ever I try, I usually have a respond that the sever is not correct that I should verify

Run Time Error'3075': Syntax Error(Missing Operator) in query expression [ 6 Answers ]

I am running a database using MS Access 2000 along with Visual Basic. Inside the database I am running a specific tracking summary form that takes information from a populated main table. Inside the tracking summary form I have three combo boxes; Status, Fiscal Year and Province, with their...


View more questions Search