Addition and subtraction of 2 numbers by taking values dynamically from user in java

Write a java program to perform addition and subtraction of 2 numbers by taking values dynamically from user.

import java.util.*;
public class scanner_demo 
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int a,b;
        System.out.println("Enter the value of a:");
        a=s.nextInt();
        
        System.out.println("enter the value of b:");
        b=s.nextInt();
        
        int c=a+b;
        System.out.println("addition of two no is:"+c);
        
        float d=a-b;
        System.out.println("subtraction of two no is:"+d);     
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *