Comp. Sci Exercises 6.01-03
The floor, ceil, and round methods of the Math class all "round" in some way. What is the difference among them?
- floor always rounds down - ceil always rounds up - round rounds normally
What is the output of System.out.println(Math.min(-20,-30)); ?
-30
What is the output of System.out.println(Math.sqrt(100)); ?
10
What is the output of System.out.println(Math.abs(2.5)); ?
2.5
What is the output of System.out.println(Math.abs(-25)); ?
25
What is the output of System.out.println(Math.pow(5,2)); ?
25
What is the output of System.out.println(Math.sqrt(9)); ?
3
What is the output of System.out.println(Math.max(20,30)); ?
30
What is the output of System.out.println(Math.pow(2,5)); ?
32
What is the output of System.out.println(Math.sqrt(25)); ?
5
What is the output of System.out.println(Math.pow(4,3)); ?
64
What is the output of System.out.println(Math.floor(7.999)); ?
7
What is the output of System.out.println(Math.round(7.499)); ?
7
What is the output of System.out.println(Math.sqrt(49)); ?
7
What is the output of System.out.println(Math.ceil(7.001)); ?
8
What is the output of System.out.println(Math.round(7.5)); ?
8
What is the output of System.out.println(Math.sqrt(64)); ?
8
What is the output of System.out.println(Math.pow(3,4)); ?
81
Modules that perform a related set of functions are grouped together in a special type of container. What is this special container called?
A class
What must all program statements end with?
A semi-colon (;)
Which keywords in Java are case-sensitive?
All of them
Which programming language requires a very precise organization?
All of them
What kind of operator is the equal sign (=) ?
An assignment operator
Are PI and E "attributes" or "methods" of the Math class?
Attributes
What is the output of System.out.println(Math.sqrt("Hello")); ?
Compile Error
What spoken language is Java based on?
English
What is a parameter used for?
It provides necessary information to the method.
Programming languages require special "containers" to store their program statements. What are these containers called in Java?
Methods and classes
What is the output of System.out.println(Math.sqrt(-25)); ?
NaN
Are "method headings" and "class heading" program statements?
No
Can Math.sqrt be used without a parameter?
No
If a program does not compile, will a byte code file be created?
No
If a program has syntax errors, can it compile?
No
What do classes contain?
One or more methods
What do methods contain?
One or more program statements
Where are parameters placed?
Parameters are placed between parentheses immediately following the method identifier.
Refer to program MathMethods07.java and its output. Why does Math.pow(-1,0.5) return a value of NaN?
Taking a number to the ½ power is the same as taking its square root. That means, we are computing the square root of -1.
Refer yet again to question 19. What does the 9 signify?
The argument/parameter/information being passed/sent to the method
Refer to the previous question. What does Math signify?
The name of the class
Refer again to question 19. What does sqrt signify?
The name of the method
Why do computers exist?
To make life simpler
Can methods and attributes of the Math class be used together in the same program?
Yes
The information, which is passed to a method is called an _____________ or a _____________.
argument or a parameter
Method sqrt can compute the square root of what 2 data types?
integers (int) and real numbers (double)
List 7 Java keywords.
public, main, System, int, double, print, void
List 4 different things that can be passed as a parameter.
• a numerical constant, • a variable, • an expression , • or even another method