Ask Question
28 April, 17:09

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.

+5
Answers (1)
  1. 28 April, 19:48
    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?
Get 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 & 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