1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ExtremeBDS [4]
3 years ago
14

Java Programming Challenge Description:Write a program that, given two binary numbers represented as strings, prints their sum i

n binary. The binary strings are comma separated, two per line. The final answer should not have any leading zeroes. In case the answer is zero, just print one zero i.e. 0Input:Your program should read lines from standard input. Each line contains two binary strings, separated by a comma and no spaces.Output:For each pair of binary numbers print to standard output their binary sum, one per line.Test 1Test InputDownload Test Input110011,1010Expected OutputDownload Test Output111101Test 2Test InputDownload Test Input11010,00101001Expected OutputDownload Test Output1000011
Computers and Technology
1 answer:
Sunny_sXe [5.5K]3 years ago
8 0

Answer:

import java.util.Scanner;

public class DecimalToBinary {

   public static String convertToBinary(int n) {

       if(n == 0) return "0";

       String binary = "";

       while (n > 0) {

           binary = (n % 2) + binary;

           n /= 2;

       }

       return binary;

   }

   public static int convertToDecimal(String binary) {

       int n = 0;

       char ch;

       for(int i = 0; i < binary.length(); ++i) {

           ch = binary.charAt(i);

           n = n*2 + (ch - '0');

       }

       return n;

   }

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       String[] words = in.nextLine().split(",");

       System.out.println(convertToBinary(convertToDecimal(words[0].trim()) + convertToDecimal(words[1].trim())));

       in.close();

   }

}

Explanation:

You might be interested in
Which of the following is true about binary search. A. It uses binary numbers in its algorithm B. It is slower than sequential s
trapecia [35]

Answer:

<u> A. It uses binary numbers in its algorithm</u>

Explanation:

A Binary search is a type of algorithm designed to look through <em>only </em>a sorted array of data for a particular item.

It is<em> more efficient (faster) </em>than sequential search since the algorithm doesn't have to look up the entire array of data, but simply repeatedly divide in half the section of the array that could contain the searched item.

4 0
3 years ago
What do people in japan use to make anime
lions [1.4K]

software programming like adobe flash.

8 0
3 years ago
To add a hyperlink to your presentation, select the text, choose Hyperlink from the Insert menu, and then
Elan Coil [88]

Answer:

I guessed D, taking it right now, sorry if it's wrong

Explanation:

6 0
3 years ago
Ethereum Mining Calculator Profitability and Difficulty Level?
yanalaym [24]

Profitability Calculator: https://www.cryptocompare.com/mining/calculator/eth?HashingPower=200&HashingUnit=MH%2Fs&PowerConsumption=140&CostPerkWh=0.12&MiningPoolFee=1

Difficulty Level Chart: https://www.coinwarz.com/difficulty-charts/ethereum-difficulty-chart

3 0
3 years ago
If you are writing an algorithm and you aren’t confident that you understand the problem, what can you do?
Zigmanuir [339]

Answer:

divide it into smaller pieces

Explanation:

Usually, the main reason a programmer does not understand a problem fully is that there is too much information. The best way to try and fully understand a problem is to divide it into smaller pieces. Start off by answering the question what is the expected output for an input. Then divide each individual issue within the problem. This will allow you as a programmer/developer to create an individual solution for each individual issue within the problem and then test to make sure that the input gives the correct output.

8 0
3 years ago
Other questions:
  • Which of the following are examples of software? Check all of the boxes that apply.
    12·2 answers
  • Which option allows you to view slides on the full computer screen?
    11·1 answer
  • What encryption method is used by WPA for wireless networks?
    7·1 answer
  • Write the definition of a function printAttitude , which hasan int parameter and returns nothing. The function prints amessage t
    13·1 answer
  • When a visitor clicks the submit button on a form, the ______ of each form element is sent?
    12·2 answers
  • Identify any eight new programming languages and classify them based on their functionality.
    14·2 answers
  • . Select the advantages of RAID-5 relative to other RAID schemes. (MAY SELECT MULTIPLE)
    7·1 answer
  • The Advanced Properties sheet enables you to add which of the following?
    15·1 answer
  • Which properties would be useful to know to search for a Word document? Check all that apply.
    7·1 answer
  • in a particular factory, a team leader is an hourly paid production worker who leads a small team. in addition to hourly pay, te
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!