
whats the error..............
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;
}
}
}

hi friend,
you are defining the add and sub method at the wrong place. Try the code below :
package roseindia.net;
import java.util.Scanner;
public class g {
public static void main(String[] args) {
int d,x,y;
int a;
Scanner s=new Scanner(System.in);
System.out.println("Enter the first number");
x=s.nextInt();
System.out.println("Enter the second number");
y=s.nextInt();
System.out.println("Enter ur choice");
System.out.println("1 For Add.");
System.out.println("2 For Subtract.");
a=s.nextInt();
switch(a)
{ case 1:add(x,y);
break;
case 2:sub(x,y);
break;
default :System.out.println("invalid choice");
break;
}
}
public static void add(int x, int y){
int d= x+y;
System.out.println("Addition of two numbers : "+d);
}
public static void sub(int x, int y){
int d= x-y;
System.out.println("Subtraction of two numbers : "+d);
}
}

thanx dear