U3: Predefined Methods Flashcards
1
Q
Method [A]
A
- Has own name
- Action already written
- Stored in separate file “class” having name
2
Q
Method [B]
A
- Needs info to be sent
- Can return data to main program
- Can be executed from main program
3
Q
Passing Arguments
A
Information sent to a method
4
Q
Outputting Math Methods
A
System.outprintln(Math.method(num1, num2))
5
Q
max
A
- Maximum of two numbers
- int num1 = 34; int num2 = 12;
- Output: 34
6
Q
min
A
- Minimum of two numbers
- int num1 = 34; int num2 = 12;
- Output: 12
7
Q
pow
A
- First input to power of 2nd
- int num1 = 2; int num2 = 6;
- Output: 64
8
Q
abs
A
- Absolute value
- double num = -34.214;
- Output: 34.214
9
Q
hypot
A
- (num1^2 + num2^2)^½:
- int sideA = 4; int sideB = 3;
- Output: 5
10
Q
ceil
A
- Rounded up nearest integer
- double num = 82.114;
- Output. 82.0
11
Q
floor
A
- Rounded down nearest integer
- double num = 87.876
- Output: 87.0
12
Q
sqrt
A
- Square root of number
- double num = 64;
- Output: 8.0
13
Q
round
A
- Rounded to nearest integer
- double num = 64.545
- Output: 65
14
Q
random
A
- Positive double value between 0.0 and 1.0
- System.out.println(Math.random());
- Possible Output: 0.1311034762657053
15
Q
toDegrees
A
- Angle in radians to degrees
- double angle1 = 0.7853981633974483;
- Output: 45
16
Q
toRadians
A
- Angle in degrees to radians
- double angle1 = 45;
- Output: 0.7853981633974483
17
Q
sin
A
- Sine for angle
- double angle1 = 45;
- Output: 0.649448048
18
Q
cos
A
- Cosine for angle
- double angle1 = 45;
- Output: 0.760405965
19
Q
External Class
A
Separate area from main program that contains methods program uses
20
Q
tan
A
- Tangent for angle
- double angle1 = 45;
- Output: 0.854080685
21
Q
Passing Arguments
A
“Passing” data from main program to method
22
Q
Arguments
A
- Variables passed in method call
- Inside brackets after name of method
23
Q
Types of Arguments
A
Integers, Doubles, etc
24
Q
Parameters
A
- Defined in method definition
- Appear when writing actual method
25
words.[starts/ends]With(“string”)
Returns boolean value if string starts/ends with specific word
26
Method Call
The use of a method to pass data
27
Finding Location of Character
- Location stated as integers; starts at 0
- Ex: p of “Computer”: 3
28
words.charAt(integer)
Returns character located at integer position in string
29
words.toUpper()
Converts string to all uppercase
30
words.toLower()
Converts string to all lowercase
31
[variable].replace(“oldChars”, “newChars”)
Replaces character/set of characters in string with new characters/set of characters
32
[variable].length()
Returns no. of characters in string
33
[variable].lastIndexOf(“string”)
Outputs location where stated characters are last found
34
[variable].indexOf(“string”)
- Returns integer where stated characters are first found in string
- Returns -1 if not found