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
What is the simplest way to convert a decimal number in a binar one in c++?
Fiesta28 [93]
It's easy you need to use function for decimal in binary.
binary STD;
int STD_no;
STD=STD_No.ToBinary

4 0
3 years ago
What is renewable energy
Marat540 [252]
Renewable energy is energy that is collected from renewable resources, which are naturally replenished on a human timescale, such as sunlight, wind, rain, tides, waves, and geothermal heat.
8 0
3 years ago
Cisco cyber security would classify this email?
Nookie1986 [14]

Cisco cyber security would classify this email as security threats.

<h3>How do Cisco cyber security classify email security threats?</h3>

They classify them as:

  • Malware Delivery via Spam.
  • Credential Theft
  • Business Email Compromise, etc.

Note that in the case above, Cisco cyber security would classify this email as security threats

Learn more about Cisco from

brainly.com/question/23388335

#SPJ12

8 0
1 year ago
Which best describes a paraphrase?
Anna11 [10]
To rewrite something , but in your own words
4 0
3 years ago
Import simplegui
victus00 [196]

Answer:

ooh....

Explanation:

For example, to convert from bar to pounds per square inch you would multiply by 100000 then divide by 6894.757. Or, multiply by 100000/6894.757 = 14.503774. So, to convert directly from bar to pounds per square inch, you multiply by 14.503774.

3 0
3 years ago
Other questions:
  • A database on a mobile device containing bands, sub-bands and service provider IDs allowing the device to establish connection w
    9·1 answer
  • Isaac is researching Abraham Lincoln’s life for a social studies report. He finds an encyclopedia that includes original letters
    5·2 answers
  • What network setting do i need for a workgroup?
    5·1 answer
  • Give big-O estimate for the number of operations (multiplication or addition) used in the following algorithm segment (ignore co
    15·1 answer
  • 25 Points Discuss games you have played that have poor game design puzzles and how you might improve them.
    10·1 answer
  • For each 8-bit data frame the layer uses a generator polynomial G(x) = x4+x2+ x+1 to add redundant bits. What is the sequence of
    11·1 answer
  • What best describes "broadband access"?
    13·1 answer
  • 1. Select two forms of case designed suitable for ATX power supply and
    13·1 answer
  • Which feature of REPL.it would you use to transmit your program to a friend?
    12·1 answer
  • Is it true that if the user log out the computer will turn off automatically​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!