High Fashioners Issue # 2 | 页面 238

J. E. N. I.
Di bawah ini adalah program yang menunjukkan bagaimana method-method tersebut digunakan. class MathDemo { public static void main( String args []) {
System. out. println(" absolute value of-5: " + Math. abs(-5));
System. out. println(" absolute value of 5: " + Math. abs(-5));
System. out. println(" random number( max value is 10): " + Math. random()* 10);
System. out. println(" max of 3.5 and 1.2: " + Math. max( 3.5, 1.2));
System. out. println(" min of 3.5 and 1.2: " +
Math. min( 3.5, 1.2)); System. out. println(" ceiling of 3.5: " + Math. ceil( 3.5)); System. out. println(" floor of 3.5: " + Math. floor( 3.5)); System. out. println(" e raised to 1: " + Math. exp( 1)); System. out. println(" log 10: " + Math. log( 10)); System. out. println(" 10 raised to 3: " + Math. pow( 10,3)); System. out. println(" rounded off value of pi: " +
Math. round( Math. PI)); System. out. println(" square root of 5 = " + Math. sqrt( 5)); System. out. println(" 10 radian = " + Math. toDegrees( 10) +
" degrees ");
System. out. println(" sin( 90): " + Math. sin( Math. toRadians( 90)));
}
}
Ini adalah contoh output dari program yang dibuat. Coba jalankan program dan bereksperimenlah secara bebas dengan memberikan argument.
absolute value of-5: 5 absolute value of 5: 5 random number( max value is 10): 4.0855332335477605 max of 3.5 and 1.2: 3.5 min of 3.5 and 1.2: 1.2 ceiling of 3.5: 4.0 floor of 3.5: 3.0 e raised to 1: 2.7182818284590455 log 10: 2.302585092994046 10 raised to 3: 1000.0 rounded off value of pi: 3 square root of 5 = 2.23606797749979 10 radian = 572.9577951308232 degrees sin( 90): 1.0
Pengenalan Pemrograman 2 3