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
One advantage of a resource like the World Wide Web is that it connects people with problems to people who have__
Nezavi [6.7K]

Answer:

Answers

Explanation:

5 0
3 years ago
How to connect canon printer to computer?
denpristay [2]
<span>Step 1Determine what type of connection you need for your computer and printer. If you see a large rectangular connection on your printer it is a parallel printer, and you will need to make sure you have a parallel port on your computer. This connection will be long and rectangular, and it may be red in color. If your Canon printer has a small square connection on the back it is a USB printer, and you will need to look for a flat slot on your computer to hook it up.Step 2Connect the printer and computer. If you are working with a parallel printer connect the large end of the cable to the back of the printer and the smaller end to the computer. If you have a USB printer, connect the square end of the cable to the back of the printer and the flat end to a free USB port on your computer.Step 3Turn on your printer and the computer. Insert the print cartridges that come with the printer. Watch the lower right-hand corner of your computer screen for a "found new hardware" message. This is your indication that the operating system has found your new printer and is installing the proper driver for it.Step 4Insert the CD that comes with your printer, if you are prompted to do so. If your operating system was unable to find a suitable driver it will prompt you for the CD. Keep your CD handy anyway, because you will need it to install the printer utilities.Step 5Insert the CD and allow it to install your printer utilities. After the utilities are installed you will be prompted to clean and align the print heads on your new printer. After the print heads have been aligned your new Canon printer will be ready for use.hope this helps</span>
7 0
3 years ago
Consider five wireless stations, A, B, C, D, and E.
klio [65]

Answer:

Check the explanation

Explanation:

A) Whenever C is sending to D, what other communications are possible?

C’s packet will be seen by A, B and D, but not by E. Thus, D can send to E at the sametime..

B) Whenever B is sending to A, what other communications are likely?

Even though B’s packet will not be seen by D, other nodes, e.g., E, or C, can’t send to D since the packets from these nodes will interfere with the packets from B at A. Therefore, other communications is not likely at the same time.

C) Whenever B is sending to C, what other communications are possible?

B’s packet will be seen by E, A and C, by not by D. therefore, E can send to D at the same point.

4 0
3 years ago
Define a method named swapValues that takes an array of four integers as a parameter, swaps array elements at indices 0 and 1, a
Luba_88 [7]

The program is an illustration of arrays.

Arrays are used to hold multiple values.

The program in java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main{

   //This defines the method

public static int[] swapValues(int[] arr) {

   //This swaps the first and second array elements

       int temp = arr[0];

       arr[0] = arr[1];   arr[1] = temp;

   //This swaps the third and fourth array elements

       temp = arr[2];

       arr[2] = arr[3];   arr[3] = temp;

   //This returns the swapped array to main

       return arr;

}

//The main method begins here

   public static void main(String[] args) {

       //This creates a Scanner object

       Scanner input = new Scanner(System.in);

 //This declares an array of 4 elements

 int[] intArray = new int[4];

 //This gets input for the array

 for(int i = 0; i<4;i++){

     intArray[i] = input.nextInt();

 }

 //This calls the swapValues method

 intArray=swapValues(intArray);

 //This prints the swapped array

 for (int i = 0; i < 4; i++){

 System.out.print( intArray[i]+ " ");     }

}  

}

At the end of the program, the elements are swapped and printed.

Read more about similar programs at:

brainly.com/question/14017034

6 0
3 years ago
How can a PowerPoint user add a shadow to a table
damaskus [11]
Https://wordribbon.tips.net/T010192_Drop_Shadows_for_Tables.html
8 0
3 years ago
Other questions:
  • Why is there more content on youtube in 4k then there is on cable, satellite, and digital tv combined?
    6·2 answers
  • ________ is a dedicated device designed to manage encrypted connections established over an untrusted network such as the Intern
    12·1 answer
  • JavaBeans are?A special Java classfileServletsAppletsA Special form of JSPNone of Given
    8·1 answer
  • A word I know, six letters it contains, remove one letter and 12 remains, what is it?
    8·1 answer
  • What is the purpose of a system call in an operating system?
    10·1 answer
  • If a user inserts a piece of clip art over some text but does not want the art to block the text, the user should select
    14·2 answers
  • When making an assembly of design what command is most.commonly used?
    15·1 answer
  • 4.15 LAB: Password modifier
    14·1 answer
  • One of the primary principles of the Rapid Application Development methodology is early prototyping of the _______ in the develo
    6·1 answer
  • 10. Differentiate between equity share &amp; preference share.​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!