1. Trang chủ
  2. » Giáo án - Bài giảng

sach song ngu hoc tieng anh cho lap trinh vien 4

54 8 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

FILE TK TRANG TRI TAI LIEU Sách HỌC TIẾNG ANH SONG NGỮ cho LẬP TRÌNH VIÊN ( Phần 1 ) HỆ THỐNG ĐÀO TẠO LẬP TRÌNH HIỆN ĐẠI Phiên bản 1 0 Tháng 02 2022 LỜI MỞ ĐẦU Lập trình viên muốn giỏi tiếng Anh như gi.

HỆ THỐNG ĐÀO TẠO LẬP TRÌNH HIỆN ĐẠI Sách HỌC TIẾNG ANH SONG NGỮ cho LẬP TRÌNH VIÊN (Phần 1) Phiên 1.0 - Tháng 02/2022 while(!(success = try())); LỜI MỞ ĐẦU Lập trình viên muốn giỏi tiếng Anh "như giỏi code", phương pháp học đơn xem phim, học qua hát, video việc học qua mẫu song ngữ có highlight cụm từ quan trọng vô thú vị hiệu "Sách Song Ngữ Cho Lập Trình Viên (Phần 1)" biên tập theo chương "Principles, Patterns, and Practices" từ sách "Agile Software Development" tác giả Robert C Martin Nội dung kể nhân vật Alphonse, sinh viên IT trường nhận vào thực tập cơng ty ơng C (chính tác giả) Thơng qua câu chuyện, tình huống, học đặt chân vào ngành công nghiệp phần mềm kể lại từ góc nhìn Alphonse, bạn có thể: - Được tiếp cận với ngơn ngữ chuẩn - Được mở mang hiểu biết thông qua nguồn kiến thức, ý tưởng tác giả từ mẫu Anh - Việt - Vừa tiếp xúc với tiếng Anh, vừa ơn lại tốn lập trình Mặc dù đội ngũ biên tập CodeGym nỗ lực việc hoàn thiện sách với tiêu chí dễ hiểu, khoa học hiệu quả, nhiên khó để tránh khỏi sai sót q trình biên soạn Vì vậy, mong nhận ý kiến phản hồi đóng góp người thơng qua email marketing@codegym.vn Cảm ơn bạn tải đọc "Sách Song Ngữ Cho Lập Trình Viên (Phần 1)" Đừng quên chia sẻ tài liệu để có thêm động lực biên soạn phần sách Thân, Ban biên tập while(!(success = try())); LỜI MỞ ĐẦU Thợ lành nghề #1 - Mở đầu Thảm họa Thợ lành nghề #2 - Chế độ ăn kiêng tăng cường Thợ lành nghề #3:Tính rõ ràng cộng tác 16 Thợ lành nghề #4 - Bài kiểm tra tính kiên nhẫn 24 Thợ lành nghề #5: Bước nhỏ 30 Danh sách từ vựng tổng hợp 45 PHỤ LỤC: TÀI NGUYÊN LẬP TRÌNH 52 www.codegym.vn / Page 02 while(!(success = try())); Thợ lành nghề #1 - Mở đầu Thảm họa 13 February 2002, Dear Diary, Ngày 13 tháng năm 2002 Nhật ký thân mến, Today was a disaster – I really messed it up I wanted so much to impress the journeymen here, but all I did was make a mess Ngày hôm thảm hoạ – Tôi làm hỏng chuyện Tôi muốn gây ấn tượng với ngài “cựu học việc” rốt làm rối tung lên It was my first day on the job as an apprentice to Mr C I was lucky to get this apprenticeship Mr C is a well-recognized master of software development The competition for this position was fierce Ðó ngày tơi làm chân thực tập ông C Tôi may mắn có vị trí Ơng C người có tiếng làng phát triển phần mềm Cuộc thi để giành chân học việc nảy lửa Mr C’s apprentices often become Những người theo học ông C thường journeymen in high demand It means trở thành người thợ lành something to have worked with Mr C nghề đánh giá cao Ðiều có nghĩa làm việc với ơng C có giá trị rõ ràng I thought I was going to meet him today, but instead a journeyman named Jerry took me aside He told me that Mr C always puts his apprentices through an orientation Tôi ngỡ hôm gặp ông C, bị gã “cựu học việc” Jerry níu qua bên Gã bảo ơng C luôn yêu cầu phần định hướng cho người học việc ngày đầu www.codegym.vn / Page 03 while(!(success = try())); during their first few days He said this orientation was to introduce apprentices to the practices that Mr C insists we use, and to the level of quality he expects from our code Gã nói ơng C cho phần định hướng thiết thực với người học việc, chất lượng mã nguồn mà ông mong đợi họ This excited me greatly It was an opportunity to show them how good a programmer I am So I told Jerry I couldn’t wait to start He responded by asking me to write a simple program for him He wanted me to use the Sieve of Eratosthenes to calculate prime numbers He told me to have the program, including all unit tests, ready for review just after lunch Tôi háo hức kinh khủng Ðây hội để tơi cho họ thấy tay lập trình giỏi cỡ Thế tơi bảo Jerry không chờ Gã đáp lại háo hức cách bảo thử viết chương trình đơn giản Gã muốn tơi dùng Sàng Eratosthenes (Sieve) để tính số nguyên tố Gã cịn bảo tơi phải chuẩn bị xong chương trình bao gồm trọn kiểm thử đơn vị để soát sau buổi ăn trưa This was great! I had almost four hours to whip together a simple program like the Sieve I am determined to a really impressive job Listing shows what I wrote I made sure it was well commented, and neatly formatted Thật tuyệt! Tơi có gần đồng hồ để “xào nấu” chương trình đơn giản Sieve Tơi tâm làm chương trình thật ấn tượng Tơi viết mã Mã dẫn Tơi nắm chương trình thích cẩn thận trình bày gọn gàng Mã dẫn /** * This class generates prime numbers up to a user-specified maximum * The algorithm used is the Sieve of Eratosthenes <p> Eratosthenes of Cyrene, b.c * 276 BC, Cyrene, Libya; d.c.194 BC,Alexandria He was the first man to * calculate the circumference of the Earth, and was also known for working on * calendars with leap years and running the library at Alexandria.</p> * The * algorithm is quite simple: Given an array of integers starting at 2, cross * out all multiples of Find the next uncrossed integer, and cross out all of * its multiples * Repeat until you have passed the square root of the maximum * value * @authorAlphonse, www.codegym.vn / Page 04 while(!(success = try())); * @version 13 Feb 2002 atp */ import java.util.*; public class GeneratePrimes { /** * @param maxValue is the generation limit */ public static int[] generatePrimes(int maxValue) { if (maxValue >= 2) { // the only valid case // declarations int s = maxValue + 1; // size of array boolean[] f = new boolean[s]; int i; // initialize array to true for (i = 0; i < s; i++) { f[i] = true; } // get rid of known non-primes f[0] = f[1] = false; // sieve int j; for (i = 2; i < Math.sqrt(s) + 1; i++) { if (f[i]) { // if i is uncrossed, cross its multiples for (j = * i; j < s; j += i) f[j] = false; // multiple is not prime } } // how many primes are there? int count = 0; for (i = 0; i < s; i++) { if (f[i]) { count++; // bump count } } int[] primes = new int[count]; // move the primes into the result for (i = 0, j = 0; i < s; i++) { if (f[i]) // if prime www.codegym.vn / Page 05 while(!(success = try())); { } } } primes[j++] = i; } return primes; // return the primes } else // maxValue < { return new int[0]; // return null array if bad input } Then I wrote a unit test for GeneratePrimes It is shown in Listing It uses the JUnit framework as Jerry had instructed It takes a statistical approach; checking to see if the generator can generate primes up to 0, 2, 3, and 100 Sau viết kiểm thử đơn vị cho GeneratePrimes Xem mã Mã dẫn Ðoạn mã dùng khung làm việc JUnit Jerry hướng dẫn Nó tiếp cận kiểu thống kê; kiểm tra xem “generator” tạo số nguyên tới 0, 2, 100 In the first case there should be no primes In the second there should be one prime, and it should be In the third there should be two primes and they should be and In the last case there should be 25 primes, the last of which is 97 Trong trường hợp thứ hẳn khơng có số ngun Trong trường hợp thứ hai phải có số nguyên phải số Trường hợp thứ ba có hai số nguyên chúng số Trường hợp cuối phải 25 số nguyên số cuối phải 97 If all these tests pass, then I assumed that the generator was working I doubt this is foolproof, but I couldn’t think of a reasonable scenario where these tests would pass and yet the function would fail Nếu kiểm thử đạt, tơi giả định “generator” chạy Tơi e khó tin cậy tuyệt đối cách trên, không nghĩ kịch xảy mà hàm sai bước kiểm thử Mã dẫn import junit.framework.*; import java.util.*; public class TestGeneratePrimes extends TestCase { public static void main(String args[]) { junit.swingui.TestRunner.main(new String[]{"TestGeneratePrimes"}); www.codegym.vn / Page 06 while(!(success = try())); } } public TestGeneratePrimes(String name) { super(name); } public void testPrimes() { int[] nullArray = GeneratePrimes.generatePrimes(0); assertEquals(nullArray.length, 0); int[] minArray = GeneratePrimes.generatePrimes(2); assertEquals(minArray.length, 1); assertEquals(minArray[0], 2); int[] threeArray = GeneratePrimes.generatePrimes(3); assertEquals(threeArray.length, 2); assertEquals(threeArray[0], 2); assertEquals(threeArray[1], 3); int[] centArray = GeneratePrimes.generatePrimes(100); assertEquals(centArray.length, 25); assertEquals(centArray[24], 97); } I got all this to work in about an hour Jerry didn't want to see me until after lunch, so I spent the rest of my time reading the Design Patterns book that Jerry gave me Tôi làm việc khoảng đồng Jerry không muốn gặp trước bữa ăn trưa, thế, dành trọn thời gian lại đọc Design Patterns mà Jerry đưa cho After lunch I stopped by Jerry’s office, and told him I was done with the program He looked up at me with a funny grin on his face and said: “Good, let's go check it out.” Sau buổi ăn trưa, tơi ghé văn phịng Jerry cho gã biết thực xong chương trình Gã nhìn tơi cười, nói: “Ðược lắm, xem thử nào.” He took me out into the lab and sat me down in front of a workstation He sat next to me He asked me to bring up my program on this machine So I navigated to my laptop on the network and brought up the source files Sau bữa trưa, gã dẫn vào phịng máy cho tơi ngồi trước máy Gã ngồi bên cạnh yêu cầu đưa chương trình tơi vào máy Thế tơi kết nối laptop với mạng chuyển mã nguồn lên www.codegym.vn / Page 07 while(!(success = try())); Jerry looked at the two source files for about five minutes Then he shook his head and said: “You can’t show something like this to Mr C! If I let him see this, he’d probably fire both of us He’s not a very patient man.” Jerry xem xét hai mã nguồn chừng năm phút gã lắc đầu bảo: “Mày đưa cho ông C xem được! Nếu tao để ơng xem này, ơng sa thải hai Ơng khơng phải người kiên nhẫn đâu.” I was startled, but managed to keep Tơi đánh thót cố giữ my cool enough to ask: “What’s bình tĩnh hỏi gã: “Vậy sai chỗ wrong with it?” nào?” Jerry sighed “Let's walk through this together,” he said “I’ll show you, point by point, how Mr C wants things done.” Jerry thở dài nói: “Tụi lược qua đống Tao hướng dẫn chi tiết cho mày cách ông C muốn.” “It seems pretty clear,” he continued, “that the main function wants to be three separate functions The first initializes all the variables and sets up the sieve The second actually executes the sieve, the third loads the sieved results into an integer array.” “Khá rõ ràng”, gã tiếp tục, “rằng nên tách hàm main thành ba hàm riêng biệt Hàm thứ khởi tạo tất biến thiết lập “sieve” Hàm thứ hai thực thi hành “sieve” hàm thứ ba tải kết “sieve” vào dãy số nguyên.” I could see what he meant There Tôi nhận ý gã Có ba khái were three concepts which were niệm chơn hàm Tuy vậy, buried in that function Still, I didn’t gã muốn tơi phải làm see what he wanted me to about it Gã nhìn tơi lúc, rõ ràng He looked at me for a while, clearly đợi xem phản ứng Nhưng rốt expecting me to something But gã thở dài, lắc đầu và… finally he heaved a sigh, shook his head, and Thợ lành nghề #2 - Chế độ ăn kiêng tăng cường and continued “To expose these tiếp tục “Ðể diễn tả rõ ba khái three concepts more clearly, I want niệm này, tao muốn mày tách chúng www.codegym.vn / Page 08 while(!(success = try())); you to extract them into three separate methods Also get rid of all the unnecessary comments and pick a better name for the class When you are done with that, make sure all the tests still run.” thành ba hàm riêng biệt Ðồng thời bỏ hết thích khơng cần thiết tìm tên cho lớp Khi làm xong thứ đó, mày phải bảo đảm kiểm thử chạy được.” You can see what I did in Listing I’ve marked my changes in bold, just like Martin Fowler does in his Refactoring book I changed the name of the class to a noun, got rid of all the comments about Eratosthenes, and made three methods out of the three concepts in the generatePrimes function Các bạn thấy tơi làm Mã dẫn Tôi in đậm để đánh dấu thay đổi, tương tự Martin Fowler trình bày Tái cấu trúc Tơi đổi tên lớp thành danh từ, bỏ hết thích Eratosthenes tạo ba hàm tương ứng với ba khái niệm hàm generatePrimes Extracting the three functions forced me to promote some of the variables of the function to static fields of the class Jerry said that this made it much clearer which variables are local and which have wider influence Việc tách thành ba hàm bắt phải đưa số biến cục hàm thành thuộc tính lớp Jerry nói cách thể rõ biến cục biến hàm có ảnh hưởng rộng Mã dẫn PrimeGenerator.java, phiên PrimeGenerator.java, phiên /** * This class Generates prime numbers up to a user specified maximum The * algorithm used is the Sieve of Eratosthenes Given an array of integers * starting at 2: Find the first uncrossed integer, and cross out all its * multiples Repeat until the first uncrossed integer exceeds the square root * of the maximum value */ import java.util.*; public class PrimeGenerator { private static int s; private static boolean[] f; private static int[] primes; www.codegym.vn / Page 09 while(!(success = try())); public void testSix() throws Exception { int factors[] = PrimeFactorizer.factor(6); assertEquals(2, factors.length); assertContains(factors, 2); assertContains(factors, 3); } private void assertContains(int factors[], int n) { String error = "assertContains:" + n; for (int i = 0; i < factors.length; i++) { if (factors[i] == n) { return; } } fail(error); } “Yikes! That one passed too!” I cried “Úi! Cái kiểm thử ổn luôn!” rú lên “Interesting.” Nodded Jerry “Seven is “Lý thú.” Jerry gật gù “Vậy chạy going to work too, isn’t it?” phải không?” “Yeah, I think it is.” “Vâng, nghĩ vậy.” “Then let's skip it and go for eight “Vậy bỏ thẳng tới 8, That one can’t pass!” khơng qua trường hợp đâu!” He was right Eight had to fail because Gã Với trường hợp the factorRegister array was too small hỏng mảng factorRegister nhỏ public void testEight() throws Exception { int factors[] = PrimeFactorizer.factor(8); assertEquals(3, factors.length); www.codegym.vn / Page 39 while(!(success = try())); } assertContainsMany(factors, 3, 2); private void assertContainsMany(int factors[], int n, int f) { String error = "assertContains(" + n + "," + f + ")"; int count = 0; for (int i = 0; i < factors.length; i++) { if (factors[i] == f) { count++; } } } if (count != n) { fail(error); } “What a relief! It failed!” “Ðúng nhẹ nhõm! hỏng rồi!” “Yeah,” said Jerry, “for an array out of bounds exception You could get it to pass by increasing the size of factorRegister, but that wouldn’t be more general.” “Ừa.” Jerry đáp “Vì vượt q ngoại lệ kích thước mảng Mày làm vượt qua cách gia tăng kích thước factorRegister cách khơng tổng qt “Let’s try it anyway, and then we’ll Thì thử xem giải solve the general problem of the array vấn đề chiều dài mảng sau.” size.” So I changed the to a in the Thế đổi thành hàm initialize function, and got a green bar initialize tơi có màu xanh “OK,” I said, “what is the maximum “Được rồi,” tơi nói “tối đa thừa số number of factors that a number can mà số có bao nhiêu?” have?” “I think it’s something like log2 of the “Tao nghĩ logarit số số number.” said Jerry phải.” Jerry nói “Wait!” I said, “Maybe we’re chasing “Đợi đã!” Tơi nói, “Có thể www.codegym.vn / Page 40 while(!(success = try())); our tail What is the largest number lòng vòng Số lớn we can handle? Isn’t it 2^64?” xử lý mấy? mũ 64 sao?” “I’m pretty sure it can’t be larger than Jerry đáp “Tao khơng thể lớn số đó.” that,” said Jerry “OK, then let's just make the size of “Được rồi, thử tạo chiều dài the factorRegister 100 That’s big factorRegister 100 Nó lớn đủ enough to handle any number we để xử lý số quẳng cho nó.” throw at it “Fine by me.” said Jerry “A hundred “Ðược thơi.” Jerry nói “100 số ngun chẳng có phải lo.” integers is nothing to worry about.” We tried it, and the tests still ran Chúng thử điều kiểm thử chạy I looked at Jerry and said: “The next Tơi nhìn Jerry nói: “kiểm thử tiếp test case is nine That’s certainly going theo tơi Chắc chắn to fail.” hỏng.” “Let's try it.” he said Gã đáp “Thì thử đi.” So I typed in the following: Vậy viết mã sau: public void testNine() throws Exception { } int factors[] = PrimeFactorizer.factor(9); assertEquals(2, factors.length); assertContainsMany(factors, 2, 3); “Good, that failed.” I said “Making it pass should be simple I just need to remove as a special number in findPrimeFactors, and use both and with some general algorithm.” So I modified findPrimeFactors as follows: “Trời, hỏng thật.” Tơi nói “Vượt qua trường hợp đơn giản Tôi cần bỏ số đặc biệt findPrimeFactors dùng cho thuật toán tổng quát.” Thế điều chỉnh hàm findPrimeFactors sau: www.codegym.vn / Page 41 while(!(success = try())); private static void findPrimeFactors(int multiple) { } for (int factor = 2; multiple != 1; factor++) { for (; (multiple % factor) == 0; multiple /= factor) { factorRegister[factorIndex++] = factor; } } “OK, that passes.” Said Jerry “Now “Được rồi, chạy” Jerry nói “Bây what’s the next failing test case?” xem thử kiểm thử hỏng?” “Well, the simple algorithm I used will divide by non-primes as well as primes That won’t work right That’s why my first version of the program was divided only by primes “Ừm, thuật tốn đơn giản tơi dùng để chia từ số phi nguyên tố lẫn số nguyên tố Kiểu không thực cho nên phiên đầu chương trình chia từ số nguyên tố The first non-prime the algorithm will Thuật toán đầu dành cho số phi divide by is four, so I imagine 4X4 will nguyên tố chia fail mường tượng 4X4 hỏng public void testSixteen() throws Exception { } int factors[] = PrimeFactorizer.factor(16); assertEquals(4, factors.length); assertContainsMany(factors, 4, 2); “Ouch! That passes.” I said “How “Ui! Cái kiểm thử chạy rồi.” Tôi could that pass?” nói “Làm qua nhỉ?” “It passes, because all the twos have been removed before you try to divide by four, so four is never found as a factor Remember, it also wasn’t found as a factor of or 4!” “Nó qua tất số loại bỏ trước mày thử chia cho 4, nên không nhận thừa số Nên nhớ, không thấy thừa số với 8, 4!” www.codegym.vn / Page 42 while(!(success = try())); “Of course!” I said “All the primes are removed before their composites The fact that the algorithm checks the composites is irrelevant But that means I never needed the array of prime numbers that I had in my first version.” “Tất nhiên!” trả lời “Tất số nguyên tố bị dời bỏ trước đa hợp Thật thuật tốn dùng để kiểm tra đa hợp khơng liên quan hết, điều có nghĩa tơi không cần dãy số nguyên tố phiên ban đầu mình.” “Right.” said Jerry “That’s why I “Ðúng thế.” Jerry nói “Ðó lý tao xố nó.” deleted it.” “Vậy xong? Mình hồn thành phải không?” “Is this it then? Are we done?” “Can you think of a failing test case?” Jerry hỏi: ” Mày nghĩ test case bị hỏng không?” asked Jerry? “I don’t know.” I said “Let's try 1000.” “Tôi nữa, thử 1000 đi.” Tôi trả lời “Ah, the shotgun approach OK, give “À, tiếp cận kiểu mạnh bạo Được rồi, thử đi.” it a try.” public void testThousand() throws Exception { } int factors[] = PrimeFactorizer.factor(1000); assertEquals(6, factors.length); assertContainsMany(factors, 3, 2); assertContainsMany(factors, 3, 5); “That worked! OK, how about ” We tried several other test cases, they all passed This version of program was much simpler than first version, and was faster too “Nó chạy ln! Được rồi, hay là…” but the my No Chúng viết nhiều kiểm thử khác ổn Phiên chương trình đơn giản phiên nhiều www.codegym.vn / Page 43 while(!(success = try())); wonder Jerry deleted the first one chạy nhanh Hèn chi Jerry xoá phiên đầu What amazed me, and still amazes me, is that we snuck up on the better solution one test case at a time I don’t think I would ever have stumbled upon this simple approach had we not been inching forward one simple test case at a time Ðiều làm kinh ngạc cịn làm tơi kinh ngạc sau kiểm thử lại tiến gần với giải pháp Nếu không tiến lên với kiểm thử tơi khơng nghĩ đến theo cách đơn giản Tơi khơng biết chuyện xảy với I wonder if that happens in bigger dự án lớn nữa? Hôm học đôi điều projects? I learned something today www.codegym.vn / Page 44 while(!(success = try())); 7ӯYӵQJ MRXUQH\PHQ PDNHDPHVV DSSUHQWLFH ZHOOUHFRJQL]HG VRIWZDUHGHYHORSPHQW ILHUFH KLJKGHPDQG RULHQWDWLRQ OHYHORITXDOLW\ RSSRUWXQLW\ SURJUDPPHU SULPHQXPEHU XQLWWHVW ZKLSWRJHWKHU LPSUHVVLYH FRPPHQWHG QHDWO\ LQVWUXFWHG VWDWLVWLFDO FDVH DVVXPHG VFHQDULR JULQ VKRRNVEG VKHDG ILUH SDWLHQW VWDUWOHG NHHSFRRO VLJKHG ZDONWKURXJK FOHDU 3KLrQkP ‫ޖ‬G‫ޝܮݤ‬QLPԥQ PHܼNԥPHV ԥ‫ޖ‬SUHQWܼV ZHO‫ޖ‬UHNԥܳQDܼ]G ‫ޖ‬V‫ܥ‬IWZHԥUGܼ‫ޖ‬YHOԥSPԥQW IܼԥV KDܼGܼ‫ޖ‬P‫ޝܤ‬QG ‫ޝܧޙ‬ULHQ‫ޖ‬WHܼ‫ݕ‬ԥQ ‫ޖ‬OHYԥOԥY‫ޖ‬NZ‫ܥ‬OԥWL ‫ܥޙ‬Sԥ‫ޖ‬W‫ݕ‬X‫ޝ‬QԥWL ‫ޖ‬SUԥ‫ܳݜ‬U PԥU SUDܼP‫ޖ‬Q‫ݞ‬PEԥU ‫ޖ‬MX‫ޝ‬QܼWWHVW ZܼSWԥ‫ܳޖ‬HèԥU ܼP‫ޖ‬SUHVܼY ‫ޖ‬N‫ܥ‬PHQW ‫ޖ‬QL‫ޝ‬WOL ܼQ‫ޖ‬VWU‫ݞ‬NW VWԥ‫ޖ‬WܼVWܼNԥO NHܼV ԥ‫ޖ‬VMX‫ޝ‬P Vܼ‫ޖ‬Q‫ޝܤ‬ULԥ‫ݜ‬ ܳUܼQ ‫ݜݕ‬N IDܼԥU ‫ޖ‬SHܼ‫ݕ‬ԥQW ‫ޖ‬VW‫ޝܤ‬WԥOG NL‫ޝ‬SNX‫ޝ‬O VDܼ Z‫ޝܧ‬NșUX‫ޝ‬ NOܼԥU 1JKƭD FӵXKӑFYLӋF WҥRPӝWPӟKӛQÿӝQ KӑFQJKӅ ÿѭӧFF{QJQKұQ SKiWWULӇQSKҫQPӅP FăQJWKҷQJ 1KXFҫXFDR VӵÿӏQKKѭӟQJ PӭFÿӝFKҩWOѭӧQJ FѫKӝL OұSWUuQKYLrQ VӕQJX\rQWӕ NLӇPWUDÿѫQYӏ ҩQWѭӧQJ ÿmQKұQ[pW JӑQJjQJ KѭӟQJGүQ WKӕQJNr WUѭӡQJKӧS JLҧÿӏQK NӏFKEҧQ FѭӡLWRHWRpW OҳFÿҫX VDWKҧL NLrQQKүQ JLұWPuQK JLӳEuQKWƭQK WKӣGjL ÿLTXD WK{QJWKRiQJ www.codegym.vn / Page 45 while(!(success = try())); VHSDUDWH LQLWLDOL]H H[HFXWH ORDG LQWHJHUDUUD\ FRQFHSW EXULHG KHDYHG H[SRVH H[WUDFW XQQHFHVVDU\ JHWULGRI LQEROG UHIDFWRU IRUFHG YDULDEOH VWDWLFILHOG FOHDUHU ORFDO LQIOXHQFH PHVV\ FOHDQVWKXS H[SUHVVLYH LQQDUGV GHVFULSWLYH UHDGDEOH GRXEOHQHJDWLYHV LQLWLDOL]DWLRQ LQGH[ LQQHUORRS FRQIXVLQJ ‫ޖ‬VHSԥUԥW ܼ‫ޖ‬Qܼ‫ݕ‬ԥODܼ] ‫ޖ‬HNVܼNMX‫ޝ‬W Oԥ‫ݜ‬G ‫ܼޖ‬QWܼG‫ݤ‬ԥUԥ‫ޖ‬UHܼ ‫ޖ‬N‫ܥ‬QVHSW ‫ޖ‬EHUL KL‫ޝ‬Y ܼN‫ޖ‬VSԥ‫]ݜ‬ ܼN‫ޖ‬VWU NW ‫ݞ‬Q‫ޖ‬QHVԥVHUL ܳHWUܼGԥY ܼQEԥ‫ݜ‬OG UL‫ޖ‬I NWԥU I‫ޝܧ‬VW ‫ޖ‬YHԥULԥEԥO ‫ޖ‬VW WܼNIL‫ޝ‬OG ‫ޖ‬NOܼԥUԥU ‫ޖ‬Oԥ‫ݜ‬NԥO ‫ܼޖ‬QIOXԥQV ‫ޖ‬PHVL NOL‫ޝ‬Q‫ݞ‬S ܼN‫ޖ‬VSUHVܼY ‫ܼޖ‬QԥG] Gܼ‫ޖ‬VNUܼSWܼY ‫ޖ‬UL‫ޝ‬GԥEԥO ‫ޖ‬G‫ݞ‬EԥO‫ޖ‬QHܳԥWܼY L‫ޙ‬QL6+ԥOԥ‫]ޖ‬Ɨ6+ ԥ Q ‫ܼޖ‬QGHNV ܼQԥUOX‫ޝ‬S NԥQ‫ޖ‬IMX‫ܼ]ޝ‬ƾ ULrQJUӁ NKӣLWҥR WKLKjQK WҧL PҧQJVӕQJX\rQ éWѭӣQJ FK{Q SKұSSKӗQJ OӝUD WUtFK[XҩW NK{QJFҫQWKLӃW WKRiWNKӓL LQÿұP FҩXWU~FOҥL EӏpS %LӃQ WUѭӡQJWƭQK U}UjQJKѫQ ÿӏDSKѭѫQJ ҧQKKѭӣQJ OӝQ[ӝQ GӑQGҽS ELӇXFҧP EӝSKұQ P{Wҧ FyWKӇÿӑFÿѭӧF SKӫÿӏQKNpS VӵNKӣLWҥR PөFOөF YzQJWURQJ Jk\QKҫPOүQ www.codegym.vn / Page 46 while(!(success = try())); LWHUDWHXS HPXODWH H[SODQDWRU\ GHDOWZLWK JHWWKHKDQJRI PLVFHOODQHRXV EDUHO\ JHRPHWULF IUDJPHQW KDQJVWRJHWKHU VFRZO PHHNO\ UHDGWKURXJK LPSURYHPHQW UHOHYDQW PXOWLSOH JUDE DSSURYDO WDNHQDEDFN VTXDUHURRW FDOFXODWH VKHHSLVKO\ UHZULWH UDWLRQDOH DSSURSULDWHO\ EDUN JXOS IUDFWLRQDO LWHUDWLRQOLPLW OLWWHU LQFUHPHQW ‫ܼޖ‬WԥUHܼW‫ݞ‬S ‫ޖ‬HPMԥOHܼW ܼN‫ޖ‬VSO QԥWԥUL GL‫ޝ‬OZܼè ܳHWèL‫ޝ‬K ƾԥY ‫ޙ‬PܼVԥO‫ޖ‬HܼQLԥV ‫ޖ‬EHԥOL ‫ޙ‬G‫ݤ‬L‫ޝ‬ԥ‫ޖ‬PHWUܼN ‫ޖ‬IU ܳPԥQW K ƾWԥ‫ܳޖ‬HèԥU VND‫ݜ‬O ‫ޖ‬PL‫ޝ‬NOL ‫ޖ‬UL‫ޝ‬G‫ޙ‬șUX‫ޝ‬ ܼP‫ޖ‬SUX‫ޝ‬YPԥQW ‫ޖ‬UHOԥYԥQW ‫ޖ‬P‫ݞ‬OWܼSԥO ܳU E ԥ‫ޖ‬SUX‫ޝ‬YԥO WHܼNԥ‫ޖ‬E N ‫ޙ‬VNZHԥ‫ޖ‬UX‫ޝ‬W ‫ޖ‬N ONMԥOHܼW ‫ݕޖ‬L‫ޝ‬Sܼ‫ݕ‬OL ‫ޙ‬UL‫ޖޝ‬UDܼW ‫ޙ‬U ‫ݕ‬ԥ‫ޖ‬Q‫ޝܤ‬O ԥ‫ޖ‬SUԥ‫ݜ‬SULԥWOL E‫ޝܤ‬N ܳ‫ݞ‬OS ‫ޖ‬IU N‫ݕ‬ԥQԥO ‫ܼޙ‬WԥU‫ޖ‬Hܼ‫ݕ‬ԥQ‫ޖ‬OܼPܼW ‫ޖ‬OܼWԥU ‫ܼޖ‬ƾNUԥPԥQW OһSOҥL WKLÿXD JLҧLWKtFK [ӱOê KLӇXYLӋF EDRKjP YӯDÿӫ KuQKKӑF PLӃQJ JҳQEyYӟLQKDX FDXFy KLӅQOjQK ĈӑFTXD VӵFҧLWLӃQ OLrQTXDQWKtFKKӧS QKLӅX YӗOҩ\ SKrGX\ӋW VӱQJVӕW FăQEұFKDL WtQKWRiQ QJѭӧQJQJQJ YLӃWOҥL FѫVӣOêOXұQ WKtFKKӧS WUXWUpR QXӕWQѭӟFEӑW SKkQVӕ JLӟLKҥQOһSOҥL [ҧUiF WăQJ www.codegym.vn / Page 47 while(!(success = try())); SDUDQRLG VLOO\ QHUYRXV QDJJLQJ FRYHUHG JUXPEOHG LPSDWLHQW DOOD\ UHOHQWHG VFUROO GHDGLQWKHH\H PRGXOH ODVWORQJ VWULGHRII WRSQRWFK EULOOLDQFH FROODERUDWLRQ FODULW\ LQGLYLGXDO RXWFRPH JUXII DWWLWXGH GLVFRXUDJHG IRONV GULIWLQJ FRQIOLFWHG IUDQNO\ SROLVK DUJXPHQW YHQWXUHG GLVEHOLHI ‫ޖ‬S UԥQ‫ܼܧ‬G ‫ޖ‬VܼOL ‫ޖ‬Q‫ޝܮ‬YԥV ‫ޖ‬Q ܼܳƾ ‫ޖ‬N‫ݞ‬YԥU ‫ܳޖ‬U‫ݞ‬PEԥO ܼP‫ޖ‬SHܼ‫ݕ‬ԥQW ԥ‫ޖ‬OHܼ Uܼ‫ޖ‬OHQW VNUԥ‫ݜ‬O GHGܼQèL‫ޝ‬Dܼ ‫ޖ‬P‫ܥ‬G‫ݤ‬X‫ޝ‬O O‫ޝܤ‬VWO‫ܥ‬ƾ VWUDܼG‫ܥ‬I ‫ޙ‬W‫ܥ‬S‫ޖ‬Q‫ܥ‬W‫ݕ‬ ‫ޖ‬EUܼOMԥQV Nԥ‫ޙ‬O Eԥ‫ޖ‬UHܼ‫ݕ‬ԥQ ‫ޖ‬NO UԥWL ‫ܼޙ‬QGܼ‫ޖ‬YܼG‫ݤ‬XԥO ‫ޖ‬D‫ݜ‬WN‫ݞ‬P ܳU‫ݞ‬I ‫ޖ‬ WܼW‫ݕ‬X‫ޝ‬G Gܼ‫ޖ‬VN‫ݞ‬UܼG‫ݤ‬G IR‫ݜ‬NV GUܼIW NԥQ‫ޖ‬IOܼNWܼG ‫ޖ‬IU ƾNOL ‫ޖ‬S‫ܥ‬Oܼ‫ݕ‬ ‫ܳޝܤޖ‬MԥPԥQW ‫ޖ‬YHQW‫ݕ‬ԥU ‫ޙ‬GܼVEܼ‫ޖ‬OL‫ޝ‬I KRDQJWѭӣQJ QJӕF OROҳQJ FҵQQKҵQ ÿӅFұS FjXQKjX QyQJQҧ\ [RDGӏX PӫLOzQJ FXӝQ[XӕQJ OҥQKOQJ P{ÿXQ WӗQWҥLOkX VҧLEѭӟF ÿӍQKFDR ViQJFKyL VӵKӧSWiF WURQJWUҿR FiQKkQ NӃWFөF FӝFFҵQ 7KiLÿӝ QҧQOzQJ KӝL WU{LGҥW PkXWKXүQ WKҷQJWKҳQ ÿiQKEyQJ WKDPVӕ PҥRKLӇP VӵKRjLQJKL www.codegym.vn / Page 48 while(!(success = try())); WHVW\ DVVHUW GXPEIRXQGHG IXULRXV UHDFKRYHU SUHVWLJH EUXWH DSSUHQWLFHVKLS FRPSOLPHQWDU\ WKRXJKW UDFH JODUH FDOPO\ VSXWWHUHG LQWHOOLJHQW YHVWHG WKURZDZD\ EDWFKRI EOXUWHG YDOXH DFFLGHQWDOO\ HIIRUW GLVN ZLQFHG QRG NQRZLQJO\ UHFUHDWH UHIXWH IHOW ZKHWKHU UHJUHW ‫ޖ‬WHVWL ԥ‫ޖ‬V‫ޝܮ‬W ‫ޙ‬G‫ݞ‬P‫ޖ‬ID‫ݜ‬QGܼG ‫ޖ‬IM‫ݜ‬ԥULԥV UL‫ޝ‬W‫ޖݕ‬ԥ‫ݜ‬YԥU SUHV‫ޖ‬WL‫ݤޝ‬ EUX‫ޝ‬W ԥ‫ޖ‬SUHQWܼV‫ܼݕ‬S ‫ޙ‬N‫ܥ‬PSOܼ‫ޖ‬PHQWԥUL ș‫ޝܧ‬W UHܼV ܳOHԥU ‫ޖ‬N‫ޝܤ‬POL ‫ޖ‬VS‫ݞ‬WԥU ܼQ‫ޖ‬WHOܼG‫ݤ‬ԥQW ‫ޖ‬YHVWܼG șUԥ‫ݜ‬ԥ‫ޖ‬ZHܼ E W‫ݕ‬ԥY EO‫ܮ‬UW ‫ޖ‬Y OMX‫ޝ‬ ‫ޙ‬ NVܼ‫ޖ‬GHQWԥOL ‫ޖ‬HIԥW GܼVN ZܼQV Q‫ܥ‬G ‫ޖ‬Qԥ‫ܼݜ‬ƾOL ‫ޙ‬UL‫ޝ‬NUL‫ޖ‬HܼW Uܼ‫ޖ‬IMX‫ޝ‬W IHOW ‫ޖ‬ZHèԥU Uܼ‫ܳޖ‬UHW FӭQJUҳQ NKҷQJÿӏQK FKӃWOһQJ JLұQGӳ YѭѫQWӟL X\WtQ YNJSKX VӵKӑFYLӋF FDQJӧL êQJKƭ FXӝFÿXD FKyLPҳW ÿLӅPWƭQK OҳSEҳS WK{QJPLQK EiPUӏW YӭWÿL O{ EXӝWPLӋQJ JLiWUӏ WuQKFӡ FӕJҳQJ ÿƭD QKăQPһW JұWÿҫX Fӕê WiLWҥR EiFEӓ FҧPWKҩ\ OLӋX KӕLWLӃF www.codegym.vn / Page 49 while(!(success = try())); LQVWDQW VWUXFWXUH ZRXQGXS DVWRQLVKPHQW YDOLG XVHIXO YLHZ VXJJHVW DJDLQVW VLOHQW GLVDJUHHPHQW SDWHQWO\ DEVXUG UHDFWHG UHWXUQ FRPSLOH DEVXUGLW\ VLPSOH KXPRU KXIIDQGSXII SURYH UHVSRQG EHQHDWK GULS VDUFDVP LQFUHGXORXV IDLOXUH ,PSDWLHQWO\ RGG EULJKW QRQVHQVH ‫ܼޖ‬QVWԥQW ‫ޖ‬VWU‫ݞ‬NW‫ݕ‬ԥU ‫ޙ‬ZD‫ݜ‬QG‫ݞޖ‬S ԥ‫ޖ‬VW‫ܥ‬Qܼ‫ݕ‬PԥQW ‫ޖ‬Y OܼG ‫ޖ‬MX‫ޝ‬VIԥO YMX‫ޝ‬ Vԥ‫ޖ‬G‫ݤ‬HVW ԥ‫ܳޖ‬HQVW ‫ޖ‬VDܼOԥQW ‫ޙ‬GܼVԥ‫ܳޖ‬UL‫ޝ‬PԥQW ‫ޖ‬SHܼWԥQWOL ԥE‫ޖ‬V‫ޝܮ‬G UL‫ޖ‬ NW Uܼ‫ޖ‬W‫ޝܮ‬Q NԥP‫ޖ‬SDܼO ԥE‫ޝܮ]ޖ‬GܼWL ‫ޖ‬VܼPSԥO ‫ޖ‬KMX‫ޝ‬PԥU K‫ݞ‬I QGS‫ݞ‬I SUX‫ޝ‬Y Uܼ‫ޖ‬VS‫ܥ‬QG Eܼ‫ޖ‬QL‫ޝ‬ș GUܼS ‫ޖ‬V‫ޝܤ‬N ]ԥP ܼQ‫ޖ‬NUHG‫ݤ‬ԥOԥV ‫ޖ‬IHܼOMԥU ܼP‫ޖ‬SHܼ‫ݕ‬ԥQWOL ‫ܥ‬G EUDܼW ‫ޖ‬Q‫ܥ‬QVԥQV OұSWӭF NӃWFҩX TXҩQOҥL VӵNLQKQJҥF FyJLiWUӏ FytFK 4XDQJFҧQK JӧLê FKӕQJOҥL LPOһQJ EҩWÿӗQJêNLӃQ QKҽQKjQJ QJӟQJҭQ SKҧQӭQJ WUҧYӅ ELrQGӏFK VӵY{Oê JLҧQGӏ FKLӅXOzQJ WKӣKәQKӇQ FKӭQJWӓ WUҧOӡL ӣWUrQ FKӍFKLӃW PӍDPDL NK{QJWLQ WKҩWEҥL 6ӕWUXӝW EҩWWKѭӡQJ ViQJFKyL Y{Oê www.codegym.vn / Page 50 while(!(success = try())); GLP LJQRUH JHQHUDO EUDLQFHOOV FORVHU ULGLFXORXV SUHVXPH PRGLILFDWLRQ FRQFHUWHG DWKDQG JDOOHG PHVV\ VFUXQFKXS URWWHQ REMHFWHG HYROYH REOLJLQJO\ VWDUHG LQWULJXHG DQWLFLSDWHG UHOLHI H[FHSWLRQ LQFUHDVH FKDVLQJWDLO KDQGOH DOJRULWKP PRGLILHG GLYLGH FRPSRVLWH LUUHOHYDQW DSSURDFK GܼP ܼܳ‫ޖ‬Q‫ޝܧ‬U ‫ޖ‬G‫ݤ‬HQԥUԥO EUHܼQVHO NOԥ‫]ݜ‬HU Uܼ‫ޖ‬GܼNMԥOԥV SUܼ‫]ޖ‬MX‫ޝ‬P ‫ޙ‬P‫ܥ‬GܼIܼ‫ޖ‬NHܼ‫ݕ‬ԥQ NԥQ‫ޖ‬V‫ޝܮ‬WܼG  WK QG ܳ‫ޝܧ‬O ‫ޖ‬PHVL VNU‫ݞ‬QW‫ݞݕ‬S ‫ޖ‬U‫ܥ‬WԥQ ‫ܥޖ‬EG‫ܼݤ‬NW ܼ‫ޖ‬Y‫ܥ‬OY ԥ‫ޖ‬EODܼG‫ܼݤ‬ƾOL VWHԥU ܼQ‫ޖ‬WUL‫ܳޝ‬  Q‫ޖ‬WܼVܼSHܼW Uܼ‫ޖ‬OL‫ޝ‬I ܼN‫ޖ‬VHS‫ݕ‬ԥQ ܼQ‫ޖ‬NUL‫ޝ‬V W‫ݕ‬HܼVWHܼO ‫ޖ‬K QGԥO ‫ޖ‬ OܳԥUܼèԥP ‫ޖ‬P‫ܥ‬GܼIDܼG Gܼ‫ޖ‬YDܼG ‫ޖ‬N‫ܥ‬PSԥ]ܼW ܼ‫ޖ‬UHOԥYԥQW ԥ‫ޖ‬SUԥ‫ݜ‬W‫ݕ‬ OӡPӡ /jPOѫ FKXQJ WӃEjRQmR JҫQKѫQ OӕEӏFK SKӓQJÿRiQ VӵVӱDÿәL SKӕLKӧS WURQJWҫPWD\ NKyFKӏX OӝQ[ӝQ WKXGӑQ WKӕLUӳD SKҧQÿӕL WLӃQKyD PDQJѫQ QKuQFKҵPFKҵP EӏWKXK~W GӵÿRiQWUѭӟF VӵFӭXWӃ QJRҥLOӋ WăQJ ÿLOzQJYzQJ [ӱOê WKXұWWRiQ VӱDÿәL FKLD ÿDKӧS NK{QJOLrQTXDQ FiFKWLӃSFұQ www.codegym.vn / Page 51 while(!(success = try())); DPD]HG VQHDNXS VWXPEOHXSRQ LQFKLQJ ԥ‫ޖ‬PHܼ]G VQLN‫ݞ‬S ‫ޖ‬VW‫ݞ‬PEԥOԥ‫ޖ‬S‫ܥ‬Q ܼQW‫ݕ‬ NLQKQJҥF OҿQOrQ YҩSQJm QKtFKWӯQJFK~W www.codegym.vn / Page 52 ... four, so I imagine 4X4 will nguyên tố chia fail mường tượng 4X4 hỏng public void testSixteen() throws Exception { } int factors[] = PrimeFactorizer.factor(16); assertEquals (4, factors.length);... làm Hơm qua chúng tơi viết chương trình tạo số ngun tố Dị tìm thừa số ngun tố vấn đề xuyên qua danh sách số nguyên tố xét thử có thừa số từ số nguyên định So I grabbed the keyboard and began... để chia từ số phi nguyên tố lẫn số nguyên tố Kiểu không thực cho nên phiên đầu chương trình chia từ số nguyên tố The first non-prime the algorithm will Thuật toán đầu dành cho số phi divide by

Ngày đăng: 31/08/2022, 10:01

Xem thêm: