TAILIEUCHUNG - Programming with Java, Swing and Squint phần 8

Menu này sẽ xuất hiện một mình trong một cửa sổ như thể hiện trong hình . Trong ngày, nó là sáng bên ngoài. Theo đó, khi "AM" mục trình đơn trong chương trình của chúng tôi được chọn, nền của cửa sổ của nó sẽ có màu trắng như trong hình . Mặt khác, khi "PM" mục trình đơn được chọn, | to see if it starts with 5 . This condition however invokes nextLine again. Because each invocation of nextLine attempts to retrieve a new line from the NetConnection rather than testing to see if the first line started with 5 it would actually check whether the second line received from the server 250 Hello pleased to meet you starts with 5 . It does not so the first execution of the loop body would terminate without displaying any line. The second execution of the body would start by checking to see if the third line received 553 baduser@ Domain of address baduser@ does not exist starts with 4 . It does not so the computer would continue checking the condition of the loop looking at the fourth line 503 Need MAIL before RCPT to see if it starts with a 5 . This condition will return true. Therefore the statement n will be executed to display the line. Unfortunately since this command also invokes nextLine it will not display the fourth line. Instead it will access and display the fifth line 503 Need MAIL command Luckily this line is at least an error. A very similar scenario will play out with even worse results on the next three lines. The statement in the loop body will test to see if the sixth line 500 Command unrecognized This should not work at all starts with a 4 . Since it does not it will continue to check if the seventh line 500 Command unrecognized . starts with a 5 . Since this test returns true it will then display the eight line 221 closing connection which is not even an error message from the server The basic lesson is that a read loop should almost always execute exactly one command that invokes nextLine during each execution of the loop body. Sentinels The hasNextLine method is not the only way to determine when a read loop should stop. In fact in many situations it is not .

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.