Jan 11, 2022

Java Program To Calculate Arithmetical Operator

Write Java Program To Add Two binary Number.   In This Post We Share A Java Program Code For Add Two binary Number Entered By User And Show Output On Screen After Compile Program.

 

package com.androidpro.in;

import
java.io.BufferedReader;
import
java.io.InputStreamReader;
import
java.util.Scanner;

public class
Main {

   
public static void main(String[] args)
    {
        Scanner in =
new Scanner(System.in);
       
System.out.print("First Binary:  ");
       
String binOne = in.next();
       
System.out.print("Second Binary: ");
       
String binTwo = in.next();
        int
left = Integer.parseInt(binOne, 2);
        int
right = Integer.parseInt(binTwo, 2);
       
System.out.println("Sum of the binary numbers : " + Integer.toBinaryString(left + right));
       
System.out.println("Difference of the binary numbers : " + Integer.toBinaryString(left - right));
       
System.out.println("Product of the binary numbers : " + Integer.toBinaryString(left * right));
       
System.out.println("Quotient of the binary numbers : " + Integer.toBinaryString(left / right));
   
}

}

 

 

Output


First Binary:  000111110

Second Binary: 11110001

Sum of the binary numbers : 100101111

Difference of the binary numbers : 11111111111111111111111101001101

Product of the binary numbers : 11101001011110

Quotient of the binary numbers : 0

 

Process finished with exit code 0

Whatsapp Button works on Mobile Device only