铁路托运行李规定:行李重不超过50公斤的,托运费按每公斤0.15元计费;如超过50公斤,超过部分每公斤加收0.10元。编一程序实现自动计费功能。

时间:2025-02-15 09:21:36

练习十二

铁路托运行李规定:行李重不超过50公斤的,托运费按每公斤0.15元计费;如超过50公斤,超过部分每公斤加收0.10元。编一程序实现自动计费功能。

package lianXiTi;

import java.util.Scanner;
public class Shi_er02 {
	public static void main(String[] args) {
		System.out.println("请输入行李的重量:");
		Scanner sc=new Scanner(System.in);
		int weight=sc.nextInt();
		double total=0;
		if(weight<=50) {
			total=weight*0.15;
		}
		else {
			total=50*0.15+(weight-50)*0.25;
		}
		System.out.println("总计:"+total);
	}
	
}