method Flashcards
java predefined method for finding the absolute value
Math.abs( any number )
java predefined method for finding the bigger (max) value
Math.max(big num, small num)
java predefined method for finding a num to the power of another num
Math.pow
java predefined method for finding the smaller (min) max
Math.min
java predefined method for rounding a num
long x = Math.round
java predefined method for finding the square root
Math.sqrt
in Math.ceil, you round to the
right
ex:
double num = Math.ceil (2.4); ///3.0
double num = Math.ceil(-2.4); //-2.0
double num = Math.ceil(2.0); //2.0
in Math.floor, you round to the
left
ex:
double num = Math.ceil (2.4); ///2.0
double num = Math.ceil(-2.4); //-3.0
double num = Math.ceil(2.0); //2.0
java predefined method for giving you random numbers within a certain range
Math.random();
ex:
print number between 1000 and 1113 inclusive
System.out.println(int) ( Math.random() * 114 + 1000 );
[we take the difference between the two numbers and add 1 to it then multiply it to Math.random(), the add the smaller value between the two]
what can you write at the beginning of a code that uses a lot of Math. predefined methods?
import static java.lang.Math.*;
T/F: in a public class, there can exist public static void main only.
F, we can also have a method public static void.
T/F: in a public class, there can exist public static void main only.
F, we can also have a method public static void.
T/F: You can call out a method more than once in main.
T,
public class testM2
3 {
4 public static void main(String args[])
5 {
6 System.out.println(“welcom”) ;
7
8 mona() ;
9
10 System.out.println(“end my program”) ;
11 mona() ;
12 }
13 public static void mona()
14 {
15 System.out.println(“inside mona “) ;
16 }
T/F: You can name a method anything even if it defies the naming laws.
F, you can name it anything so long as it abides by the naming laws
the variables in a method header are called _________
formal parameter