|
001 packagepackage is used to name the directory or folder a class is in intermediate;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program java.util.*;
005 /**
006 * All about my application.
007 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
008 */
009 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 RecursionExamples
010 {open braces start code blocks and must be matched with a close brace
011 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer sum(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 nums)
012 {open braces start code blocks and must be matched with a close brace
013 returnreturn means to provide the result of the method and/or cease execution of the method immediately sum(nums, nums.length-1);
014 }close braces end code blocks and must match an earlier open brace
015
016 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer sum(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 nums, intint is the type for whole numbers and it is short for integer maxIndex)
017 {open braces start code blocks and must be matched with a close brace
018 ifif executes the next statement only if the condition in parenthesis evaluates to true(maxIndex==this is the comparison operator which evaluates to true if both sides are the same0)//base case
019 {open braces start code blocks and must be matched with a close brace
020 returnreturn means to provide the result of the method and/or cease execution of the method immediately nums[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
021 }close braces end code blocks and must match an earlier open brace
022 elseelse is what happens when the if condition is false //recursive step
023 {open braces start code blocks and must be matched with a close brace
024 returnreturn means to provide the result of the method and/or cease execution of the method immediately nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysmaxIndex]brackets are typically used to declare, initialize and index (indicate which element of) arrays+adds two numbers together or concatenates Strings togethersum(nums, maxIndex-1);
025 }close braces end code blocks and must match an earlier open brace
026 }close braces end code blocks and must match an earlier open brace
027
028 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false find(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 names, String target)
029 {open braces start code blocks and must be matched with a close brace
030 returnreturn means to provide the result of the method and/or cease execution of the method immediately find(names, target, names.length-1);
031 }close braces end code blocks and must match an earlier open brace
032
033 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false find(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 names, String target, intint is the type for whole numbers and it is short for integer maxIndex)
034 {open braces start code blocks and must be matched with a close brace
035 ifif executes the next statement only if the condition in parenthesis evaluates to true(maxIndex==this is the comparison operator which evaluates to true if both sides are the same0)
036 {open braces start code blocks and must be matched with a close brace
037 returnreturn means to provide the result of the method and/or cease execution of the method immediately names[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays.equals(target);
038 }close braces end code blocks and must match an earlier open brace
039 elseelse is what happens when the if condition is false
040 {open braces start code blocks and must be matched with a close brace
041 returnreturn means to provide the result of the method and/or cease execution of the method immediately names[brackets are typically used to declare, initialize and index (indicate which element of) arraysmaxIndex]brackets are typically used to declare, initialize and index (indicate which element of) arrays.equals(target) ||this is boolean or, meaning if either or both are true then the result is true find(names, target, maxIndex-1);
042 }close braces end code blocks and must match an earlier open brace
043 }close braces end code blocks and must match an earlier open brace
044
045 //assume nums is in order
046 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false binarySearch(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 nums, intint is the type for whole numbers and it is short for integer target)
047 {open braces start code blocks and must be matched with a close brace
048 returnreturn means to provide the result of the method and/or cease execution of the method immediately binarySearch(nums, target, 0, nums.length-1);
049 }close braces end code blocks and must match an earlier open brace
050
051 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false binarySearch(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 nums, intint is the type for whole numbers and it is short for integer target, intint is the type for whole numbers and it is short for integer start, intint is the type for whole numbers and it is short for integer end)
052 {open braces start code blocks and must be matched with a close brace
053 ifif executes the next statement only if the condition in parenthesis evaluates to true(start==this is the comparison operator which evaluates to true if both sides are the sameend)
054 {open braces start code blocks and must be matched with a close brace
055 Wiki.out.println("looking at "+adds two numbers together or concatenates Strings togethernums[brackets are typically used to declare, initialize and index (indicate which element of) arraysstart]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
056 returnreturn means to provide the result of the method and/or cease execution of the method immediately nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysstart]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;
057 }close braces end code blocks and must match an earlier open brace
058 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(end-start==this is the comparison operator which evaluates to true if both sides are the same1)
059 {open braces start code blocks and must be matched with a close brace
060 Wiki.out.println("looking at "+adds two numbers together or concatenates Strings togethernums[brackets are typically used to declare, initialize and index (indicate which element of) arraysstart]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
061 Wiki.out.println("looking at "+adds two numbers together or concatenates Strings togethernums[brackets are typically used to declare, initialize and index (indicate which element of) arraysend]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
062 returnreturn means to provide the result of the method and/or cease execution of the method immediately nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysstart]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 ||this is boolean or, meaning if either or both are true then the result is true nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysend]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;
063 }close braces end code blocks and must match an earlier open brace
064 elseelse is what happens when the if condition is false
065 {open braces start code blocks and must be matched with a close brace
066 intint is the type for whole numbers and it is short for integer middleIndex=this assignment operator makes the left side equal to the right side(start+adds two numbers together or concatenates Strings togetherend)/2;
067 Wiki.out.println("looking at "+adds two numbers together or concatenates Strings togethernums[brackets are typically used to declare, initialize and index (indicate which element of) arraysmiddleIndex]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
068 ifif executes the next statement only if the condition in parenthesis evaluates to true(nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysmiddleIndex]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)
069 {open braces start code blocks and must be matched with a close brace
070 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
071 }close braces end code blocks and must match an earlier open brace
072 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(target>nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysmiddleIndex]brackets are typically used to declare, initialize and index (indicate which element of) arrays)
073 {open braces start code blocks and must be matched with a close brace
074 returnreturn means to provide the result of the method and/or cease execution of the method immediately binarySearch(nums, target, middleIndex+adds two numbers together or concatenates Strings together1, end);
075 }close braces end code blocks and must match an earlier open brace
076 elseelse is what happens when the if condition is false
077 {open braces start code blocks and must be matched with a close brace
078 returnreturn means to provide the result of the method and/or cease execution of the method immediately binarySearch(nums, target, start, middleIndex-1);
079 }close braces end code blocks and must match an earlier open brace
080 }close braces end code blocks and must match an earlier open brace
081 }close braces end code blocks and must match an earlier open brace
082
083 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)
084 {open braces start code blocks and must be matched with a close brace
085 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 nums=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) arrays500000]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
086 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<nums.length; i++this is the increment operator, which increases the variable by 1)
087 {open braces start code blocks and must be matched with a close brace
088 nums[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()*100000);
089 }close braces end code blocks and must match an earlier open brace
090 RecursionExamples example=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RecursionExamples();
091 //Wiki.out.println("The sum is "+example.sum(nums));
092
093 Arrays.sort(nums);
094 //for(int n: nums)
095 //Wiki.out.print(n+" ");
096 //Wiki.out.println("");
097 Wiki.out.println("Looking for 5000: found="+adds two numbers together or concatenates Strings togetherexample.binarySearch(nums, 5000));
098
099 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 names=this assignment operator makes the left side equal to the right side{open braces start code blocks and must be matched with a close brace"Hello", "Goodbye", "Dolly"}close braces end code blocks and must match an earlier open brace;
100 Wiki.out.println("Goodbyes, in names? "+adds two numbers together or concatenates Strings togetherexample.find(names, "Goodbyes"));
101 }close braces end code blocks and must match an earlier open brace
102 }close braces end code blocks and must match an earlier open brace
|