Methods Flashcards
methods, char variables, and boolean
Write the General Structure of a Method
public static returntype methodname (zero or more input variables){
* // create local variables
* // do math ao logic
* // return result based on returntype (if applicable)
}
Function of “methodname” in General Structure
public static returntype methodname (zero or more input variables){
* // create local variables
* // do math ao logic
* // return result based on returntype (if applicable)
}
give a name to method
* use this name in main program to ‘call’ the method
Function of “zero or more input variables” in General Structure
public static returntype methodname (zero or more input variables){
* // create local variables
* // do math ao logic
* // return result based on returntype (if applicable)
}
take data in through input variables
- Note: variable names in main program do not have to match names in method
- Note: if there are no input values, leave ( ) blank when calling method.
- Note: the input variables do not have to match the returntype/output
Function of “returntype” in General Structure
public static returntype methodname (zero or more input variables){
* // create local variables
* // do math ao logic
* // return result based on returntype (if applicable)
}
specifies type of data being output by the method
Examples of ReturnTypes…
String
int
double
boolean
void (a.k.a. nothing)
long
char
Explain Boolean
a variable type which holds the values: true or false
- has no quotations
What word is “char” short for?
character
Special features of Char variables
can use math comparison symbols on them
Function of:
strWord.charAt(integer#)
take the single character with the index/subscript of the number in () from a given string
Write the line of code which takes a single letter in a string USING CHAR VARIABLES.
chrLetter = strWord.charAt(integer#);
Type of quotations used by char variables
single quotations
Type of quotations used by String variables
double quotations
Function of return keyword
returns a value back to main program
Which return type does not need a return keyword?
return type: void