Đang chuẩn bị liên kết để tải về tài liệu:
Lecter Java: Program design - Chapter 6: Iteration

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

In this chapter, we consider the while, for, and do-while looping constructs that control how many times a statement list is iterated (executed). Loops make programs much more powerful and capable of solving significant problems. Mastering the design and implementation of loops is an important part of a programmer's education. | Iteration Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Java looping Options while do-while for Allow programs to control how many times a statement list is executed Averaging Problem Extract a list of positive numbers from standard input and produce their average Numbers are one per line A negative number acts as a sentinel to indicate that there are no more numbers to process Observations Cannot supply sufficient code using just assignments and conditional constructs to solve the problem Don’t how big of a list to process Need ability to repeat code as needed Averaging Problem Extract a list of positive numbers from standard input and produce their average Numbers are one per line A negative number acts as a sentinel to indicate that there are no more numbers to process Algorithm Prepare for processing Get first input While there is an input to process do { Process current input Get the next input } Perform final processing Averaging . | Iteration Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Java looping Options while do-while for Allow programs to control how many times a statement list is executed Averaging Problem Extract a list of positive numbers from standard input and produce their average Numbers are one per line A negative number acts as a sentinel to indicate that there are no more numbers to process Observations Cannot supply sufficient code using just assignments and conditional constructs to solve the problem Don’t how big of a list to process Need ability to repeat code as needed Averaging Problem Extract a list of positive numbers from standard input and produce their average Numbers are one per line A negative number acts as a sentinel to indicate that there are no more numbers to process Algorithm Prepare for processing Get first input While there is an input to process do { Process current input Get the next input } Perform final processing Averaging Problem Extract a list of positive numbers from standard input and produce their average Numbers are one per line A negative number acts as a sentinel to indicate that there are no more numbers to process Sample run Enter positive numbers one per line. Indicate end of list with a negative number. 4.5 0.5 1.3 -1 Average 2.1 public class NumberAverage { // main(): application entry point public static void main(String[] args) throws IOException { // set up the list processing // prompt user for values // get first value // process values one-by-one while (value >= 0) { // add value to running total // processed another value // prepare next iteration - get next value } // display result if (valuesProcessed > 0) // compute and display average else // indicate no average to display } } Roadmap for program System.out.println("Enter positive numbers 1 per line.\n" + "Indicate end of the list with a negative number."); Scanner stdin = new Scanner(System.in); int valuesProcessed = 0; double .

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.