複製程式
import java.io.*;
public class ex5_10 {
public static void main(String[] args) throws IOException {
int time = 0, sum = 0, total = 0, total2 = 0, total3 = 0, total4 = 0;
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader buf = new BufferedReader(in);
System.out.print("請輸入整月的工作時數:");
time = Integer.parseInt(buf.readLine());
System.out.print("請輸入固定時薪:");
sum = Integer.parseInt(buf.readLine());
if (sum >= 121) {
total = 60 * sum;
total2 = (int) (sum * 1.33) * 60;
total3 = (int) (sum * 1.66) * (time - 120);
total4 = total + total2 + total3;
System.out.println("薪水為:" + total4);
} else if (sum >= 61) {
total = 60 * sum;
total2 = (int) (sum * 1.33) * (time - 60);
total3 = total + total2;
System.out.println("薪水為:" + total3);
} else {
total = time * sum;
System.out.println("薪水為:" + total);
}
}
}
其實還滿多小錯誤的也
變數名子不一樣
建議可以用一些IDE來輔助編輯
還有加一些try catch來檢查輸入的值
上面是可以run的
不過寫法是可以再改啦
小小的建議