From ggc
|
01 packagepackage is used to name the directory or folder a class is in intro;
02 importimport means to make the classes and/or packages available in this program java.util.*;
03 importimport means to make the classes and/or packages available in this program wiki.Wiki;
04
05 /**
06 * All about my application.
07 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
08 */
09 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects ProfilingSearchAndSort
10 {open braces start code blocks and must be matched with a close brace
11 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
12 {open braces start code blocks and must be matched with a close brace
13 SortingAlgorithms sorter=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor SortingAlgorithms();
14 intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays numbers=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays64000]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
15 intint is the type for whole numbers and it is short for integer timesToRun=this assignment operator makes the left side equal to the right side1000000;
16 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<numbers.length; i++this is the increment operator, which increases the variable by 1)
17 {open braces start code blocks and must be matched with a close brace
18 //fills with random numbers
19 numbers[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right side(intint is the type for whole numbers and it is short for integer)(Math.random()*10000);
20 }close braces end code blocks and must match an earlier open brace
21 Arrays.sort(numbers);
22 longlong is the type for whole numbers (they have a larger range than int) start=this assignment operator makes the left side equal to the right sideSystem.currentTimeMillis();
23 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer replications=this assignment operator makes the left side equal to the right side0; replications<timesToRun; replications++this is the increment operator, which increases the variable by 1)
24 {open braces start code blocks and must be matched with a close brace
25 intint is the type for whole numbers and it is short for integer target=this assignment operator makes the left side equal to the right side(intint is the type for whole numbers and it is short for integer)(Math.random()*10000);
26 Arrays.binarySearch(numbers, target);
27 /*forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<numbers.length; i++this is the increment operator, which increases the variable by 1)
28 {open braces start code blocks and must be matched with a close brace
29 ifif executes the next statement only if the condition in parenthesis evaluates to true(numbers[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays==this is the comparison operator which evaluates to true if both sides are the sametarget)
30 {open braces start code blocks and must be matched with a close brace
31 //do nothing
32 breakbreak terminates the loop immediately;
33 }close braces end code blocks and must match an earlier open brace
34 }close braces end code blocks and must match an earlier open brace*/
35 }close braces end code blocks and must match an earlier open brace
36 longlong is the type for whole numbers (they have a larger range than int) end=this assignment operator makes the left side equal to the right sideSystem.currentTimeMillis();
37 doubledouble is the type for numbers that can contain decimal fractions seconds=this assignment operator makes the left side equal to the right side(end-start)/1000.0/timesToRun;
38 Wiki.out.println("Filling the array took "+adds two numbers together or concatenates Strings togetherseconds+adds two numbers together or concatenates Strings together" seconds.");
39 }close braces end code blocks and must match an earlier open brace
40 }close braces end code blocks and must match an earlier open brace
|
Download/View intro/ProfilingSearchAndSort.java