05:
PARAMETERS AND
METHODS
BY PROF BASHIR M. SA’AD
CSC 2303 COMPUTER PROGRA
CS305j Introduction to
Parameters and Methods 2
Computing
•
Parameters and Methods 3
Parameters and Methods 4
public static void drawV(){
//draws a V with SIZE lines
for(int lineNum = 1; lineNum <= SIZE; lineNum++){
// print spaces before back slash
for(int j = 1; j <= lineNum - 1; j++)
[Link](" ");
[Link]("\\");
// print spaces between back slash and forward slash
for(int j = 1; j <= (SIZE - lineNum) * 2; j++)
[Link](" ");
[Link]("/");
}
}
Parameters and Methods 5
•
•
•
•
Parameters and Methods 6
•
•
•
•
•
Parameters and Methods 7
public static void oneLine13stars()
public static void oneLine7stars()
public static void draw10By3Box()
public static void draw5By4Box()
public static void draw12By100Box()
Parameters and Methods 8
•
•
•
Parameters and Methods 9
•
Parameters and Methods 10
•
Parameters and Methods 11
•
•
•
count will take the value 13
for this method call
Parameters and Methods 12
•
Output:
*************
*******
Parameters and Methods 13
•
Parameters and Methods 14
•
•
Parameters and Methods 15
•
•
Output:
24
23
Parameters and Methods 16
•
Parameters and Methods 17
•
Parameters and Methods 18
Method name Description
abs(value) absolute value
•
cos(value) cosine, in radians
log(value) logarithm base e
max(value1, value2) larger of two values
min(value1, value2) smaller of two values
pow(value1, value2) value1 to the value2 power
random() random double between 0 and 1
round(value) returns nearest whole number
sin(value) sine, in radians
sqrt(value) square root
Parameters and Methods 19
•
•
•
•
Parameters and Methods 20
•
<TYPE>
Parameters and Methods 21
•
•
•
•
•
Parameters and Methods 22
•
•
•
•
// THIS METHOD RETURNS THE FACTORIAL OF THE GIVEN INTEGER N.
// THE FACTORIAL IS THE PRODUCT OF ALL INTEGERS UP TO THAT NUMBER.
// I ASSUME THAT THE PARAMETER VALUE IS NON-NEGATIVE.
// EXAMPLE: FACTORIAL(5) RETURNS 1 * 2 * 3 * 4 * 5 = 120.
Parameters and Methods 23