- ✕この概要は、複数のオンライン ソースに基づいて AI を使用して生成されました。元のソース情報を表示するには、[詳細情報] リンクを使用します。
The following Java program takes two binary numbers as input, adds them, and outputs the result. It uses the Scanner class for input and performs binary addition without converting the numbers to decimal.
import java.util.Scanner;public class AddBinaryNumbers {public static void main(String[] args) {// Variables to store binary numbers and carrylong binary1, binary2;int i = 0, carry = 0;// Array to store the sum of binary digitsint[] sum = new int[20];// Scanner object to read inputScanner scanner = new Scanner(System.in);// Input first binary numberSystem.out.print("Enter first binary number: ");binary1 = scanner.nextLong();// Input second binary numberSystem.out.print("Enter second binary number: ");binary2 = scanner.nextLong();// Close the scannerscanner.close();// Perform binary additionwhile (binary1 != 0 || binary2 != 0) {sum[i++] = (int)((binary1 % 10 + binary2 % 10 + carry) % 2);carry = (int)((binary1 % 10 + binary2 % 10 + carry) / 2);binary1 /= 10;binary2 /= 10;}// Add remaining carry if anyif (carry != 0) {sum[i++] = carry;}// Print the result in reverse orderSystem.out.print("Sum of two binary numbers: ");while (i > 0) {System.out.print(sum[--i]);}}}コピーしました。✕コピー Java: Add two binary numbers - w3resource
2026年2月2日 · Java programming exercises and solution: Write a Java program to add two binary numbers.
Add Two Binary Numbers in Java (5 Programs)
2025年10月17日 · We will explore a Java program to add two binary numbers. The logic is simple and beginner-friendly, making it easy to understand how computers handle binary addition.
Java Program to Add Two Binary Numbers - Tutorial …
2024年12月20日 · This Java program converts the binary to integer and adds two numbers. If the two of them are of string data type, we can use the Integer …
java - Adding binary numbers - Stack Overflow
Does anyone know how to add 2 binary numbers, entered as binary, in Java? For example, 1010 + 10 = 1100.
- レビュー数: 3
Java Program to Add Two Binary Numbers - CodesCracker
Java Program to Add Two Binary Numbers: This article was created to cover some programs on the addition of two binary numbers in Java.
Java Program to Add two Binary Numbers
2018年9月7日 · In this tutorial we will write a java program to add two binary numbers. Binary number system has only two symbols 0 & 1 so a binary numbers …
Java Program to Add Two Binary Strings - GeeksforGeeks
2026年1月22日 · When two binary strings are added, the result is also a binary string. Java provides multiple ways to perform binary addition, depending on constraints such as input size and …
Java Program to add two binary numbers using ParseInt
2026年3月30日 · This program demonstrates adding two binary numbers by converting them to decimal values using Integer.parseInt () and then performing the addition.
Java Program to Add Two Binary Numbers - CodingBroz
2022年1月25日 · In this post, we will learn How to Add Two Binary Numbers in Java Programming Language. Let’s understand Binary Numbers and Binary Number …
Java Program to Add Two Binary Numbers - JavaByTechie
2022年7月9日 · That's all guys, hope this Java Program is helpful for you. Happy Learning...
- 他の人も質問しています