Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

where should i include function

  Asked By: Oscar    Date: Jan 28    Category: Java    Views: 686
  

this is a simple problem , yet i cannot
figure where to include the function add?
I get error mesage when i try to include where it is right now


import java.io.*;

class MathOp
{
public static void main(String args[])throws IOException
{
System.out.println(" MENU ");
System.out.println(" 1. ADD ");
System.out.println(" 2. SUBTRACT ");
System.out.println(" 3. MULTIPLY ");
System.out.println(" 4. DIVIDE ");
System.out.println("Enter your Choice");

BufferedReader Cin = new BufferedReader(new
InputStreamReader(System.in));
String choice;
choice =Cin.readLine();
int ch =Integer.parseInt(choice);

switch(ch)
{
case 1:
System.out.println("Add");
add();
break;
case 2:
System.out.println
("Subtract");
break;
case 3:
System.out.println
("Multiply");
break;
case 4:
System.out.println("Divide");
break;
}

/* void add()
{
System.out.println{"Add");
}
*/
}
}

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Juan Reynolds     Answered On: Jan 28

Move the 'add' function  defn to outside of 'main' but inside the class
MathOp

 
Answer #2    Answered By: Rafael Thompson     Answered On: Jan 28

are you new to java?
just pass parameters in add  func to add numbers
bye
ur soln is:

import java.io.*;

class MathOp
{
public static  void main(String args[])throws
IOException
{
System.out.println(" MENU
");
System.out.println(" 1. ADD
");
System.out.println(" 2. SUBTRACT
");
System.out.println(" 3. MULTIPLY
");
System.out.println(" 4. DIVIDE
");
System.out.println("Enter your Choice");

BufferedReader Cin = new
BufferedReader(new
InputStreamReader(System.in));
String choice;
choice =Cin.readLine();
int ch =Integer.parseInt(choice);

switch(ch)
{
case 1:

System.out.println("Add");
add();
break;
case 2:
System.out.println
("Subtract");
break;
case 3:
System.out.println
("Multiply");
break;
case 4:

System.out.println("Divide");
break;
}

}

void add()
{
System.out.println{"Add");
}


}

 
Answer #3    Answered By: Helga Miller     Answered On: Jan 28

Define outside main method.....

 
Didn't find what you were looking for? Find more on where should i include function Or get search suggestion and latest updates.




Tagged: