リンクを新しいタブで開く
    • 作業報告
    • メール
    • リライト
    • スピーチ
    • タイトル ジェネレーター
    • スマート返信
    • エッセイ
    • ジョーク
    • Instagram 投稿
    • X 投稿
    • Facebook 投稿
    • ストーリー
    • 添え状
    • 履歴書
    • 職務明細書
    • 推薦状
    • 退職願
    • 招待状
    • グリーティング メッセージ
    • その他のテンプレートを試します
  1. 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 carry
    long binary1, binary2;
    int i = 0, carry = 0;

    // Array to store the sum of binary digits
    int[] sum = new int[20];

    // Scanner object to read input
    Scanner scanner = new Scanner(System.in);

    // Input first binary number
    System.out.print("Enter first binary number: ");
    binary1 = scanner.nextLong();

    // Input second binary number
    System.out.print("Enter second binary number: ");
    binary2 = scanner.nextLong();

    // Close the scanner
    scanner.close();

    // Perform binary addition
    while (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 any
    if (carry != 0) {
    sum[i++] = carry;
    }

    // Print the result in reverse order
    System.out.print("Sum of two binary numbers: ");
    while (i > 0) {
    System.out.print(sum[--i]);
    }
    }
    }
    コピーしました。
    フィードバック
    ありがとうございました!詳細をお聞かせください
  2. Java: Add two binary numbers - w3resource

    2026年2月2日 · Java programming exercises and solution: Write a Java program to add two binary numbers.

  3. 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.

  4. 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 …

  5. 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...

    • 他の人も質問しています
      読み込んでいます
      回答を読み込めません
    このサイトを利用すると、分析、カスタマイズされたコンテンツ、広告に Cookie を使用することに同意したことになります。サード パーティの Cookie に関する詳細情報|Microsoft のプライバシー ポリシー