2009年2月24日 星期二

Homework 2-23-2009

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.

 
------------------------------------------------<程式碼開始>--------------------------------------
 public class HW02232009 {
    public static void main(String[] args)
    {
        double H11 = 4000.0/5280.0 ,H12 = 6000.0/5280.0, H13 = H11*5000.0, H14 = H12*5000.0;
        double H21 = 15.0/4.0, H22 = 4.0/15.0, H23 = 15.0 % 4.0, H24 = 4.0%15.0;
        System.out.println("1.\n4000 mile => $" + H13 + "\n6000 mile => $" + H14);
        System.out.println("\n2.\n15/4 = " + H21 + "\n4/15 = " + H22 + "\n15%4 = " + H23 + "\n4%15 = " + H24);
    }
}
------------------------------------------------<程式碼結束>--------------------------------------

沒有留言:

張貼留言