India's Largest Free Online Education Platform

Arithmetic operators in java

Arithmetic operators in java

Code:

import java.util.Scanner;
import static java.lang.System.out;
public class Arithmetic_Operator
 {  
    public static void main(String args[])
     {
         out.println("Enter any two numbers to do operation of +,-,*,/,% respectively");
    Scanner Sc= new Scanner(System.in);
    float a = Sc.nextFloat();
    float b= Sc.nextFloat();
    float c=a+b;
    float d=a-b;
    float e=a*b;
    float f=a/b;
    float g=a%b;
    out.println("Result after addition of "+a+" and "+b+" is "+c );
    out.println("Result after subtraction of "+a+" and "+b+" is "+d);
    out.println("Result after multiplication of "+a+" and "+b+" is "+e );
    out.println("Result after division of "+a+" and "+b+" is "+f );
    out.println("Result after modulus operation of "+a+" and "+b+" is "+g );
  }
}

Output:

Leave a Reply

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

error: Content is protected !!