TAILIEUCHUNG - Java™ How to Program ( Deitel - Deitel) - Phần 9

Tham khảo sách 'java™ how to program ( deitel - deitel) - phần 9', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | the programmer to use multiple initialization expressions or multiple increment expressions. For example the body of the for statement in lines 1112 of Fig. could be merged into the increment portion of the for header by using a comma as follows for int number 2 number 20 total number number 2 empty statement Page 188 Good Programming Practice Limit the size of control statement headers to a single line if possible. Good Programming Practice Place only expressions involving the control variables in the initialization and increment sections of a for statement. Manipulations of other variables should appear either before the loop if they execute only once like initialization statements or in the body of the loop if they execute once per iteration of the loop like increment or decrement statements . Application Compound Interest Calculations The next application uses the for statement to compute compound interest. Consider the following problem A person invests 1 000 in a savings account yielding 5 interest. Assuming that all the interest is left on deposit calculate and print the amount of money in the account at the end of each year for 10 years. Use the following formula to determine the amounts a p 1 r Y1 where p is the original amount invested . the principal r is the annual interest rate . use for 5 n is the number of years a is the amount on deposit at the end of the nth year. This problem involves a loop that performs the indicated calculation for each of the 10 years the money remains on deposit. The solution is the application shown in Fig. . Lines 810 in method main declare double variables amount principal and rate and initialize principal to and rate to . Java treats floating-point constants like and as type double. Similarly Java treats whole number constants like 7 and -22 as type int. Figure . Compound-interest calculations with for. This item is displayed on page 189 in the print version 1 Fig. .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.