/ Assignment / assignment_5.java
assignment_5.java
 1  /*
 2   * You are required to implement the following function , Int OperationChoices(int a, int b, int c). 
 3   * The function accepts 3 positive integers 'a', 'b' and 'c' as it's arguments. 
 4   * Implement the function to return 
 5   * (a+b) is c = 1
 6   * (a-b) if c = 2
 7   * (a*b) if c = 3
 8   * (a/b) if c = 4 
 9   */
10  import java.util.Scanner;
11  
12  public class assignment_5 {
13    public static int OperationChoices(int a, int b, int c) {
14      switch (c) {
15        case 1:
16          return (a + b);        
17  
18        case 2:
19          return (a - b);
20          
21        case 3: 
22          return (a * b); 
23      
24        case 4: 
25          return (a / b); 
26        
27        default:
28          System.out.println("Invalid input");
29          return 0;
30      }
31      
32    }
33    public static void main(String[] args) {
34      Scanner sc = new Scanner(System.in);
35      
36      System.out.print("a: ");
37      int a = sc.nextInt();
38      
39      System.out.print("b: ");
40      int b = sc.nextInt();
41      
42      System.out.print("c (1-4): ");
43      int c = sc.nextInt();
44  
45      int res = OperationChoices(a,b,c);
46      System.out.println(res);
47    }
48  }