Menu driven calculator

 Menu driven calculator


Problem Description


Menu driven calculator


The menu options are as follows:


1. Addition

2. Subtraction

3. Division

4. Multiplication

5. Modulo


The menu driven is followed by number of inputs

Logic Test Case 1


Input (stdin)

1


12


25


Expected Output


37



Logic Test Case 2


Input (stdin)

4


50


2


Expected Output


100



Code Area


import java.io.*;

import java.util.*;

public class TestClass {

public static void main(String[] args) 

     {  Scanner s= new Scanner(System.in);

 int option=s.nextInt();

 int num1=s.nextInt();

 int num2=s.nextInt();

 switch(option)

 {

 case 1:

     System.out.println(" "+(num1+num2));

 break;

 case 2:

     System.out.println(" "+(num1-num2));

 break;

 case 3:

     System.out.println(" "+(num1/num2));

 break;

 case 4: 

     if(num2!=0)

 System.out.println(" "+(num1*num2));

 break;

 case 5: 

  System.out.println(" "+(num1%num2));

     break;

 default:

     

 }

}

}



Post a Comment

0 Comments