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
Describe how you would create a Java program that prompted the user to correctly enter a username and password. The username is
schepotkina [342]

Answer:

Explanation:

The program in question would create a new Scanner Object which asks the user for the Username first. It would then save this input into a temporary variable and compare it to the actual username in the database. Since the username is not case sensitive, we would use the toLowerCase() method on both the input and the database username so that they match even if the letters are not the same case structure. If both usernames match then we would move on to ask the user for the Password and compare it with the database password for that user. Since this one is case sensitive we would compare as is. Finally, if both Username and Password match we would print "Hello World" otherwise we would print "Login Failed."

3 0
2 years ago
When do images or graphics in Microsoft Word hurt the document rather than help
Vinvika [58]

Answer:

When images or graphics excessively occupy most of the space on the page.

<u>Explanation:</u>

For example, if you observed the attached image you'll see a bad example in which the image excessively occupies most of the space on the page making the written text difficult to read.

Next, a good example of proper editing is found in the next image, which shows the written text properly aligned with the text.

3 0
3 years ago
Many subject elements make for simple and streamlined looking images. true or false
sukhopar [10]

Answer:

Explanation:

false. many elements means a complicated picture, not a simple one.

8 0
2 years ago
Which of theses is NOT one of the standard Text filters in Excel 2013?<br><br>​
aalyn [17]

Yes, it is possible to move a worksheet to open another workbook but not to copy it there. Explanation: Microsoft Excel is a powerful tool for organizing work or business-related things etc.

6 0
2 years ago
What process combines data from a list with the content of a document to provide personalized documents?
Andrej [43]
The appropriate answer is d. mail merge. Mail merge uses a database of addresses that are used to create pre-addressed mailing labels that are generally used when sending letters to a very large group. This type of application is used by utility companies or any other organizations that requires mass mailings. Mail merge is found in the Microsoft Word application. Excell spreadsheets can also be used to complete tasks similar to that of mail merge.
8 0
2 years ago
Read 2 more answers
Other questions:
  • What type of link is used to call this file
    11·1 answer
  • Today, air travel allows large numbers of people to move quickly over long distances. Which of the following is a likely effect
    8·1 answer
  • 10.
    13·1 answer
  • a paragraph is a segment of text with the same format that begins when you press the enter key and ends when you press enter key
    6·2 answers
  • A solid understanding of __________ is the foundation of verbal communication
    7·1 answer
  • How does the post process alert the user if it detects a hardware problem during the post process?
    6·1 answer
  • Hi there! I just started my beginner computer science class and I was wondering if anyone wants to help with an assignment i'm h
    15·1 answer
  • Why might a company choose Linux for its operating system instead of Microsoft Windows or Mac OS? The company's employees can sy
    13·1 answer
  • How am i able to hear a presenter from a radio station through my fm tuner​
    14·1 answer
  • DUE SOON NEED HELP FAST!!
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!