7-4 sdut-JAVA-Rental Mileage Costs
分数 14
全屏浏览
切换布局
作者 马新娟
单位 山东理工大学
A car rental company charges €1.25 per mile if the total mileage does not exceed 100 miles. If the total mileage is over 100, the company charges €1.25 for the first 100 miles, then it charges €0.30 per mile for any additional mile over 100. You are required to write a program that will be used by the administrator in the car rental company each time a car is returned. The administrator will enter the number of miles and your program will display the total price to be paid.
Input Specification:
enter the number of miles.
Output Specification:
display the total price to be paid.
Sample Input:
99
Sample Output:
Cost of 99 mile/miles is 123.75
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner; public class Main{ public static void main(String [] args) { Scanner sc=new Scanner(System.in); int n; n=sc.nextInt(); double t=0; if(n<=100&&n>=0) { t=n*1.25; System.out.println("Cost of "+n+" mile/miles is "+t); } else { t=1.25*100+(n-100)*0.3; System.out.println("Cost of "+n+" mile/miles is "+t); } } }