TAILIEUCHUNG - giáo trình Java By Example phần 7

Tham khảo tài liệu 'giáo trình java by example phần 7', 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ả | import . import . public class Applet16 extends Applet TextField textFieldl textField2 textField3 int avg1 avg2 avg3 public void init textField1 new TextField 5 textField2 new TextField 5 textField3 new TextField 5 add textField1 add textField2 add textField3 0 0 0 public void paint Graphics g http Your bowlers averages are 50 80 String s s 75 110 avg1 s s s 75 125 avg2 s s s 75 140 avg3 s public boolean action Event event Object arg repaint return true When you run Applet16 you can enter bowling scores into the three boxes at the top of the applet s display area. After you enter these averages they re displayed on-screen as well as copied into the three variables avg1 avg2 and avg3. Nothing too tricky going on here right http Now examine the listing. Remember in Chapter 10 The while and do-while Loops when you learned to keep an eye out for repetitive program code How about all those calls to getText drawString and valueOf in Listing The only real difference between them is the specific bowler s score that s being manipulated. If you could find some way to make a loop out of this code you could shorten the program significantly. How about a for loop that counts from 1 to 3 But how can you use a loop when you re stuck with three different variables The answer is an array. An array is a variable that can hold more than one value. When you first studied variables you learned that a variable is like a box in memory that holds a single value. Now if you take a bunch of these boxes and put them together what do you have You have an array. For example to store the bowling averages for your three bowlers you d need an array that can hold three values. You could call this array avg. You can even .

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.