Saturday, July 12, 2014

MENU DRIVEN PROGRAM TO FIND ARITHMETIC OPERATION IN CORE JAVA

class realcalci
{
  int ans,a,b;
  char choice;
  public void process(char choice,int a,int b)
  {
      switch(choice)
      {
          case '+':ans=a+b;break;
          case '*':ans=a*b;break;
          case '/':ans=a/b;break;
          case '-':ans=a-b;break;
          case '%':ans=a%b;break;
          default:System.out.println("not a valid choice");        
      }
      System.out.println("answer="+ans);
  }
}
public class realcalc {
     public static void main(String args[]) throws IOException
    {
        InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(in);
        System.out.println("enter two nos:");
        int a=Integer.parseInt(br.readLine());
        int b=Integer.parseInt(br.readLine());
        
        System.out.println("+.add\n*.multiply\n/.divide\n-.subtract\n%.remainder\n");
        System.out.println("enter a choice:");
        char choice=(char)br.read();
        
        realcalci obj=new realcalci();
        
         obj.process(choice,a,b);
    }
}

No comments:

Post a Comment

JAC Board Computer || IIT 2025 || Introductory Information Technology || Class 10 || Practical Examination 2025

Marks Division HOE 30 Marks IT Application Report File 20 Marks Viva - Voce 10 Marks 1) Write an HTML code to generate a web p...