Ask Question
13 July, 20:30

1. Write a program that asks for 4 separate numbers that are binary (1 or 0). Create a variable called b0 for the first, b1 for the second, b2 for the third, and b3 for the last. After gathering the four-input run the following calculation: 8b0 4b1 2b2 b3. Output the formula with the input values followed by the answer.

+2
Answers (1)
  1. 14 July, 00:17
    0
    import java. util. Scanner;

    public class CocaColaVendingTest {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter four sepertate binary numbers (1 or 0) ");

    int b0 = in. nextInt ();

    int b1 = in. nextInt ();

    int b2 = in. nextInt ();

    int b3 = in. nextInt ();

    System. out. println ("This formula / "8b0 4b1 2b2 b3/" is applied to get the following" +

    " " + (8*b0) + ", " + (4*b1) + ", " + (2*b2) + ", " + (b3));

    }

    }

    Explanation:

    This is implemented in java

    Using the scanner class, the user is prompted to enter for values (0s or 1s)

    These are received and stored in the variables b0, b1, b2, b3 as ints.

    The formula 8b0 4b1 2b2 b3 is then applied within the output statement to display the results as required by the question
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “1. Write a program that asks for 4 separate numbers that are binary (1 or 0). Create a variable called b0 for the first, b1 for the second, ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers