Practical 3


Aim:- Write a program to enter two numbers and perform mathematical operations on them.

JAVA Code :-

import java.lang.*;

class cal
{
    public static void main(String args[])
    {
        int a,b,ans;
      
        a= Integer.parseInt(args[0]);
        b= Integer.parseInt(args[1]);

        switch(args[2])
        { 
           case "+":
                       ans=a+b;
            System.out.println("Add= "+ans);
                        break;
               case "-":
                        ans=a-b;
                        System.out.println("Sub= "+ans);
                        break;
              case "*":
                        ans=a*b;
                        System.out.println("Mul= "+ans);
                        break;
              case "/":
                        ans=a/b;
                        System.out.println("Div= "+ans);
                        break;
       }
     }
}

Output:-



No comments:

Post a Comment

Programs

Home Aim:- Write a program to convert rupees to dollar. (60rupees=1 dollar). Aim:- Write a program that calculate percentage marks...