7-4 sdut-JAVA-the number of pounds worked off
分数 10
全屏浏览
切换布局
作者 马新娟
单位 山东理工大学
The number of calories burned per hour by cycling, jogging, and swimming are 200, 475, and 275, respectively. A person loses 1 pound of weight for each 3500 calories burned. Write a program that declares three variables, one to store the number of hours spent jogging, the second to store the number of hours spent cycling and the third to store the number of hours spent swimming. Assign each of these variables values. Calculate and display the number of pounds worked off.
Input Specification:
declares three variables, one to store the number of hours spent jogging, the second to store the number of hours spent cycling and the third to store the number of hours spent swimming.
Output Specification:
display the number of pounds worked off.
Sample Input:
3.5 5 4.15
Sample Output:
Total calories burned = 3803.75. Pounds lost = 1.0867857142857142.
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner; public class Main { public static void main(String [] args) { Scanner in =new Scanner(System.in); double hoursSpentJogging = in.nextDouble(); double hoursSpentCycling = in.nextDouble(); double hoursSpentSwimming = in.nextDouble(); double totalCaloriesBurned=(200*hoursSpentCycling)+(475*hoursSpentJogging)+(275*hoursSpentSwimming); double poundsLost=totalCaloriesBurned/3500; String r ="Total calories burned = " + totalCaloriesBurned + ".\n"; r += "Pounds lost = " + poundsLost + "."; System.out.println(r); } }