Ask Question
19 January, 21:13

A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 servings in the bag and that a serving equals 300 calories. Write a Java program that lets the user enter the number of cookies he or she actually ate and that then reports the number of total calories consumed.

+3
Answers (1)
  1. 19 January, 21:23
    0
    import java. util. Scanner;

    public class ANot {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("How many cookies did you eat today");

    int numOfCookies = in. nextInt ();

    double numCalories = (numOfCookies*300) / 4;

    System. out. println ("The total number of calories you consumed in "+numOfCookies+" cookies is " +

    " "+numCalories);

    }

    }

    Explanation:

    This code is implemented in Java.

    We know from the question that 4 cookies contain 300 calories Therefore number of calories consumed = (number of cookies eaten*300) / 4 To implement this in java we used the scanner class to prompt user for the input save the input to a variable and write mathematical expression for the number of calories consumed Then output the result
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 servings in the bag and that a serving ...” 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