Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
new with an array intializer.
These tips and cautions will help you write better programs and save you from agonizing over why the compiler produces error messages.
type (int [] test_scores) rather than after variable_name (int test_scores []) when declaring an array variable. Keeping all type information in one place improves the source code's readability.
java.lang.System's public static void arraycopy(Object src, int srcindex, Object dst, int dstindex, int length) method, which is the fastest way to perform the copy. (I will explore this method in a future article.)
.length (as in d.length) instead of an array's actual length. That way, you eliminate the risk of introducing length-related bugs into your code
should you later change the array's length in that array's creation code.
int [] test_scores = new long [20]; is illegal because keywords int and long represent incompatible primitive types.
new int [3] { 70, 80, 20, 30 } causes the compiler to report an error because the compiler can already determine the number of elements from the initializer.
Furthermore, the discrepancy arising from the 3 between the square brackets and four entries in the initializer signify a
probable mistake.
ArrayIndexOutOfBoundsException or an ArrayStoreException.
n x n matrix of integers from 1 to n2, such that the sum is the same for every row, column, and diagonal. If n equals 5, for example, we end up with the following matrix (where the common sum is 65):========================== | 15 | 8 | 1 | 24 | 17 | |------------------------| | 16 | 14 | 7 | 5 | 23 | |------------------------| | 22 | 20 | 13 | 6 | 4 | |------------------------| | 3 | 21 | 19 | 12 | 10 | |------------------------| | 9 | 2 | 25 | 18 | 11 | ==========================
A simple algorithm for generating a magic square when n is odd:
Express the algorithm above in pseudocode and as a Java application for any odd n.
int [] x = { }; accomplish (assuming that code fragment is legal)?
Last time, I asked you to answer two questions. Here are my answers (which appear in red).
Forgetting the closing square bracket character in a character class (e.g., [abc).
Placing a backslash prior to any alphabetic character that does not denote an escaped construct (e.g., \j). Such characters are reserved for future extensions to the regular-expression language.
(123) 555-4678.The following regex matches phone numbers according to the previous specification: (\(\d{3}\))?\s*\d{3}-\d{4}