1. Suppose you are a landscape architect who charges $5,000 per mile to landscape a highway, and suppose you know the length in feet of the high way you are working on. Write a Java program to calculate the price you charge when the length is 6000 and 4000, respectively.
Hint: There are 5280 feet in a mile.
2. Write a Java program that displays the results of the expressions 15/4, 4/15, 15%4, 4%15. Calculate the values of these expressions manually to verify that the displayed values are correct.
15/4算出來的結果為3.75。
4/15算出來的結果為0.266666666...6,程式用浮點數值只算到小數點第八位,會有誤差而得到的結果為0.26666668。
15%4為15/4的值取餘數,與程式計算結果一樣為3。
4%15為4/15的值取餘數,與程式計算結果一樣為4。
なりたい
15 年前
沒有留言:
張貼留言