Ask Question
8 December, 09:28

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.

+4
Answers (1)
  1. 8 December, 11:06
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers