【正文】
// Declare and initialize variables ? int num1 = 1。 ? (After invoking the swap method, num1 is + ? num1 + and num2 is + num2)。 ? n1 = n2。 例: double max(double num1, double num2) { if (num1 num2) return num1。 ? ? // Invoke the max method with three double parameters ? (The maximum between , , and is ? + max(, , ))。 ? else ? return num2。 cos(x) x的余弦函數(shù)值 (x以弧度為單位 ) pow (x,y) x的 y次冪 exp(x) 指數(shù)方法 e的 x次冪 sin (x) x的正弦函數(shù)值 (x以弧度為單位 ) floor(x) 不大于 x的最大整數(shù) (向下取整) sqrt (x) x的平方根 log(x) x的自然對數(shù) (以 e為底 ) ? random() Returns a random double value in the range [, ). ? cos(double a) ? tan(double a) ? acos(double a) ? asin(double a) ? atan(double a) ? Class constants: ?PI ?E 例 ? public class ComputeMeanDeviation ? { ? // Main method ? public static void main(String[] args) ? { ? int number = 0。 i10。 ? ? // Add the square of the number to squareSum ? squareSum += (number, 2)。 例 ? 輸出 ? // Display result ? (The mean is + mean)。 ? (Enter month in number between 1 and 12: )。 ? ? // Get number of days in the month ? int numOfDaysInMonth = getNumOfDaysInMonth(year, month)。 ? long totalNumOfDays = getTotalNumOfDays(year, month)。 i year。 i month。 ? ? if (month == 4 || month == 6 || month == 9 || month == 11) ? return 30。 // If month is incorrect. ? } 例 ? // Determine if it is a leap year ? static boolean isLeapYear(int year) ? { ? if ((year % 400 == 0) || ((year % 4 == 0) amp。 ? } 例 ? // Print month body ? static void printMonthBody(int startDay, int numOfDaysInMonth) ? { ? // Pad space before the first day of the month ? int i = 0。 ? for (i = 1。 ? if ((i + startDay) % 7 == 0) ? ()。 ? ( Sun Mon Tue Wed Thu Fri Sat)。 ? case 2: monthName = February。 ? case 4: monthName = April。 ? case 6: monthName = June。 ? case 8: monthName = August。 ? case 10: monthName = October。 ? case 12: monthName = December。 fac(n)=1*2*L*N,n=1(非遞歸算法) =n*(fac(n1),n=1(遞歸算法) public class ComputeFactorial { public static void main(String[] args) { // Prompt the user to enter an integer (Please enter a nonnegative integer)。 else return n*factorial(n1)。 ? int n = ()。 ? } ? } 遞歸的缺陷: 當調(diào)用一般方法時,方法里的局部變量會因為方法執(zhí)行完畢而結束生命周期。