本文主要是介绍rate.java,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import java.util.Scanner;
public class rate {
public static void main(String[] args)
{
System.out.print("请输入行驶的公里数:");
int j;
for (j = 1;; j++) {
Scanner cin = new Scanner(System.in);
int a = cin.nextInt();
if (a == 100) {
System.out.println("100公里的养路费为162.5元");
} else {
int b = a / 25;
int c = 0;
float d;
switch (b) {
case 0:
c = a * 10;
d = (float) (c / 10.0);
System.out.println(a + "公里的养路费为" + d + "元");
break;
case 1:
c = 25 * 10 + (a - 25) * 15;
d = (float) (c / 10.0);
System.out.println(a + "公里的养路费为" + d + "元");
break;
case 2:
c = 25 * 10 + 25 * 15 + (a - 50) * 20;
d = (float) (c / 10.0);
System.out.println(a + "公里的养路费为" + d + "元");
break;
case 3:
c = 10 * 25 + 25 * 15 + 25 * 20 + (a - 75) * 20;
d = (float) (c / 10.0);
System.out.println(a + "公里的养路费为" + d + "元");
break;
default:
System.out.println("输入值超出取值范围,请重新输入");
break;
}
}
}
}
}
这篇关于rate.java的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!