lec 5 Flashcards
(30 cards)
What Java class provides methods for performing mathematical operations?
Math class
What does Math.pow(2, 3) return?
8.0
How do you calculate the square root of a number in Java?
Math.sqrt(x)
What does Math.sqrt(10.5) return?
3.24
How do you find the maximum value between two numbers?
Math.max(x, y)
What does Math.max(5,10) return?
10
How do you find the minimum value between two numbers?
Math.min(x, y)
What does Math.min(2.5, 3.6) return?
2.5
How do you get the absolute (positive) value of a number?
Math.abs(x)
What does Math.abs(-2.1) return?
2.1
What does Math.random() return?
A random double between 0.0 (inclusive) and 1.0 (exclusive)
How do you generate a random integer between 0 and 9?
(int)(Math.random() * 10)
What does 50 + (int)(Math.random() * 50) return?
A random integer between 50 and 99
How do you generate a random integer between 0 and 100?
int)(Math.random() * 101)
Fill in the blank: Math._______(x, y); to get the highest value between x and y
Math.max(x, y);
Fill in the blank: Math.________(x); to find the square root of x.
Math.sqrt(x);
Fill in the blank: Math._______; to return a random number between 0 and 1
Math.random();
How do you declare a char variable in Java?
char letter = ‘A’;
What happens when you increment a char variable in Java?
It moves to the next Unicode character.
What does char ch = ‘a’; System.out.println(++ch); output?
b
What is the ASCII code for ‘0’?
48
What is the Unicode value of ‘A’?
\u0041
What is the ASCII code for lowercase ‘z’?
122
What is the numeric value of char c = ‘a’; when cast to int?
97