chipchen

|
分享:
▲
▼
改好了如下
import java.io.*; public class degree { public static void main(String args[]) throws IOException { BufferedReader buf; String str; float x,sum,sum2,sum3,total,total2=0; int y; buf = new BufferedReader(new InputStreamReader(System.in)); System.out.print("请输入货物重量:"); str = buf.readLine(); x = Float.parseFloat(str); y = 199; if ( x <= 5){ sum = x * 50; total = sum; total2 = sum + y; } else{ if ( x > 5 && x <= 10){ sum = 5 * 50; sum2 = (x - 5) * 30; total = sum + sum2; total2 = total + y;} else{ sum = 5 * 50; sum2 = 5 * 30; sum3 = (x - 10) * 20; total = sum + sum2 +sum3; } total2 = total + y; } System.out.println("货物重量:" + x); System.out.println("物流处理费:" + y); System.out.println("运费:" + total); System.out.println("物流处理费+运费:" + total2); } }
你的问题在 1.if的用法不太对 { 放错位置,且结尾的 } 没放 2.该定义浮点数的值你定义成整数 3.第一个if中total没有定义 4.第二个if的x少打 &&两边都要是逻辑式,且您的值也下错了(这不会影响编译,只是会显示出不对的值) 5.最后print的时后运费值打错(这不会影响编译,只是会显示出不对的值)
以上,请多钻研课本后的习题,应该都是蛮基本的 改写的式子请参考,不代表就一定是您的作业答案,如有错误请自行修正
此文章被评分,最近评分记录财富:40 (by codeboy) | 理由: 感谢您的回覆~ | |
|
|
|