import java.util.Scanner;
public class Test{
public static double getMoney(double w) {
If(w<=0) {
return -1;
}else if (w>2000) {
return -2;
}else {
if(w<100) {
return (Math.ceil(w/20.0)*1.2);
}else {
return (Math.ceil((w-100)/100)*2.0+(5.0*1.2));
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println(“请输入函件重量”);
int weight = sc.nextInt();
System.out.println(“邮件资费为”+getMoney(weight));
Java 根据函件重量计算资费:小于等于0返回-1;大于2000返回-2
最新推荐文章于 2022-01-14 22:51:41 发布