Chapter 4: Mathematical Functions, Characters, and Strings Flashcards
What are the trigonometric methods?
sin(radians), cos(radians), tan(radians): RETURNS AN ANGLE IN RADIANS.
toRadians(degree), toDegrees(radians): CHANGES DEGREES TO RADIANS OR RADIANS TO DEGREE.
asin(a), acos(a), and atan(a): RETURNS THE ANGLE IN RADIANS FOR INVERSE.
What are the exponent methods?
exp(x): RETURNS E TO THE POWER OF X
log(x): RETURNS THE NATURAL LOGARITHM OF X
log10(x): RETURNS THE LOG BASE OF 10 OF X
pow(a,b): RETURNS A TO THE POWER OF B
sqrt(x): RETURNS THE SQUARE ROOT OF X
What are the rounding methods?
ceil(x): x IS ROUNDED UP TO NEAREST INTEGER
floor(x): x IS ROUNDED DOWN TO NEAREST INTEGER
rint(x): x IS ROUNDED TO ITS NEAREST INTEGER. IF EQUALLY CLOSE THE EVEN NUMBER IS RETURNED AS A DOUBLE
round(x): RETURNS INT IF VALUE IS FLOAT, RETURNS LONG IF VALUE IS DOUBLE.
What is the min method?
Math.min(a, b) returns the minimum of the two numbers.
What is the max method?
Math.max(a, b) returns the maximum of the two numbers.
What is the absolute method?
Math.abs(x) returns the absolute value of a number.
What is the random method?
Math.random() returns a random number greater than or equal to 0 and less than 1.0
How to differentiate a string and a char when initializing?
A string is inside double quotations (“ “) and char is inside single quotations (‘ ‘)
Name the escape sequences for special characters.
\b - Backspace \t - Tab \n - Linefeed \f - Formfeed \r - Carriage Return \\ - Backslash \" - Double Quote Mark
What method returns the length of a string?
length();
How can you concatenate string?
You can use the + operator and the += operator to link strings
What’s the difference between the next() and nextLine() methods?
next() reads the next string that ends with a white space character, nextLine() reads the next string that ends with the Enter key.
How should you check to see if two strings are identical?
You should use the equals method instead of the == operator.
EG:
if (string1.equals(string2))
How can you specify how many decimal places you want output?
You can use the printf method. “Interest is %4.2f”
The 4 is the field width, the 2 is the precision, and the f is the conversion code.
What are some frequently used format specifiers?
%b - A boolean value %c - A character %d - A decimal integer %f - A floating-point number %e - Number in scientific notation %s - A string