lec 5 Flashcards

(30 cards)

1
Q

What Java class provides methods for performing mathematical operations?

A

Math class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does Math.pow(2, 3) return?

A

8.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you calculate the square root of a number in Java?

A

Math.sqrt(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does Math.sqrt(10.5) return?

A

3.24

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you find the maximum value between two numbers?

A

Math.max(x, y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does Math.max(5,10) return?

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you find the minimum value between two numbers?

A

Math.min(x, y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does Math.min(2.5, 3.6) return?

A

2.5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you get the absolute (positive) value of a number?

A

Math.abs(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does Math.abs(-2.1) return?

A

2.1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does Math.random() return?

A

A random double between 0.0 (inclusive) and 1.0 (exclusive)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you generate a random integer between 0 and 9?

A

(int)(Math.random() * 10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does 50 + (int)(Math.random() * 50) return?

A

A random integer between 50 and 99

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you generate a random integer between 0 and 100?

A

int)(Math.random() * 101)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: Math._______(x, y); to get the highest value between x and y

A

Math.max(x, y);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fill in the blank: Math.________(x); to find the square root of x.

A

Math.sqrt(x);

17
Q

Fill in the blank: Math._______; to return a random number between 0 and 1

A

Math.random();

18
Q

How do you declare a char variable in Java?

A

char letter = ‘A’;

19
Q

What happens when you increment a char variable in Java?

A

It moves to the next Unicode character.

20
Q

What does char ch = ‘a’; System.out.println(++ch); output?

21
Q

What is the ASCII code for ‘0’?

22
Q

What is the Unicode value of ‘A’?

23
Q

What is the ASCII code for lowercase ‘z’?

24
Q

What is the numeric value of char c = ‘a’; when cast to int?

25
What is the output of char c = 97; System.out.println(c);?
a
26
How do you declare a string variable?
String message = "Hello";
27
What class does Java use to handle strings?
String class
28
How do you find the length of a string in Java?
stringVariable.length()
29
What does System.out.println("Hello".length()); return?
5
30
How do you get the first character of a string?
stringVariable.charAt(0);