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 are characteristics of a cell
olganol [36]

Answer:

-occurs at the intersection of columns and  rows

-is a single unit for entering data on a  spreadsheet

-is located according to its cell reference or  cell address

Explanation:

A cell is a box in a spreadsheet program that contains information and each cell is identified using a cell reference that indicates the colum letter followed by the row number where the cell is located. So, according to this, the characteristics of a cell in a spreadsheet software are:

-occurs at the intersection of columns and  rows

-is a single unit for entering data on a  spreadsheet

-is located according to its cell reference or  cell address

5 0
3 years ago
What command would you issue from a command prompt to see a listing of the computers in your workgroup?
ololo11 [35]
<span>Net View is the command issue from a command prompt to see a listing of the computers in your workgroup.It will display the list of domains,computers resources which have been shared by the specified computer then it will list all computers currently in our domain.The syntax for net view using command prompt NET VIEW [\\computername [/CACHE] | [/ALL] | /DOMAIN[:domainname]].</span>
8 0
3 years ago
When installing the latest version of Internet Explorer, a dialogue box pops up with a box checked telling you that Bing will be
meriva

Answer:

B) opt-out identify

Explanation:

To opt-out means refusing to or avoiding to accept unsolicited refers to  products or service information. In this caseyou are refusing to accept Bing as your default search provider

8 0
3 years ago
(tco 3) what vbscript boolean operator could be used to replace the nested selection structure in this pseudocode? if empmedical
Leto [7]
You want both conditions to be true, so you can "And" them.
In vbscript, the and is written as "And" (not as && like other languages), so you get:

<span>If (empmedicalins = "y") And (empdentalins = "y") Then
    print empidnumber, emplastname, empfirstname
Endif</span>
3 0
3 years ago
Write code to assign the number of characters in the string rv to a variable num_chars.
kramer

Answer:

rv = "hello"

num_chars = len(rv)

print(num_chars)

Explanation:

*The code is in Python.

Initialize the string rv, in this example I set it to "hello"

Use the len() method to get the number of characters in the rv and set it to the num_chars

Print the num_chars

Note that the result will be 5 in this case, because <em>hello</em> consists of five characters

6 0
4 years ago
Other questions:
  • True or false An electronic form uses input fields in which the user can enter data from their own computer and then transmit t
    10·1 answer
  • Define a function CoordTransform() that transforms the function's first two input parameters xVal and yVal into two output param
    12·1 answer
  • 17) you need to locate an article that (1) is published by a university or proffessional association(2) is authored by clearly d
    6·1 answer
  • Which of the following is a job description for a person with a degree in information technology
    15·1 answer
  • Manuel has set up his network so that some employees can open and view files but are unable to edit them. Others can open, view,
    10·1 answer
  • The 'WIMP' environment is much more user friendly,why?​
    11·2 answers
  • Grab the stniop or they will dissapear
    12·1 answer
  • Write a program named split_me.py that accepts a string in the format Age.FirstName and returns the value FirstName is Age years
    14·1 answer
  • 2. How much did John Jones have in his account on the first day of the
    5·1 answer
  • Why did the boy run from the pillow...... wrong answers only
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!