Lecture 15, CS 302-7 and 8, February 24
i. Due tonight
i. Array variables as pointers
i. Public static void main(String[] args)
1. Underlined in this section J
i. Is this a method? Yes. But it’s kind of a special case. We’ll get to it later
i. Modularity
1. Separate code that does different things
ii. Maintainability/readability
1. Think of different methods as black boxes – once they do what they are supposed to, don’t worry about them. Like using pseudocode, kind of
iii. Reduce redundancy
1. Don’t repeate code – advantages:
a. Less typing
b. If something doesn’t work, only need to fix it one place, instead of many
i. Math.pow
ii. scanner.next
iii. random.nextInt
i. Inputs – parameters
1. can be multiple
2. declare in method header
ii. Outputs – return values
1. only one
2. specify with return statement
3. declare in method header
iii. example - Math.pow(2,3) //2^3
public static [return type] [name]([type1] param1,[type2] [param2] , …)
{
//body
}
i. Had some questions on this – when only one method, not a big deal
ii. But, when you have multiple methods, it is important
i. Other names – argument
i. Missing return values