Floating point arithmetic Flashcards

1
Q

What is the main difference between integer and floating point arithmetic?
a) Integer arithmetic does not allow negative values
b) Floating point arithmetic includes decimal precision
c) Integer arithmetic uses more memory
d) Floating point arithmetic uses only base-10 numbers

A

b) Floating point arithmetic includes decimal precision

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

What term refers to the degree of correctness in floating point operations?
a) Precision
b) Clarity
c) Accuracy
d) Scope

A

c) Accuracy

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

What is a key limitation of floating point arithmetic in computer systems?
a) It has unlimited precision
b) It only supports whole numbers
c) It introduces approximation due to binary representation
d) It cannot represent negative numbers

A

c) It introduces approximation due to binary representation

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

What is the binary representation of the decimal number 0.1?
a) 0.1
b) 0.001
c) 0.000110011001100110011001100110011
d) 0.100000001

A

c) 0.000110011001100110011001100110011

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

What causes decimal fractions like 0.1 and 0.2 to be approximations in binary?
a) Binary can only handle fractions with powers of 10
b) Binary lacks sufficient precision
c) Prime factors of decimal and binary systems differ
d) Binary numbers cannot handle fractions at all

A

c) Prime factors of decimal and binary systems differ

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

Why do 0.1f and 0.1d produce different results in Java?
a) They use different rounding methods
b) They are represented with different numbers of bits
c) They use different base systems
d) They are calculated with integer precision

A

b) They are represented with different numbers of bits

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

Which Java type allows the most precision for floating point numbers?
a) int
b) double
c) float
d) long

A

b) double

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

What is the purpose of the BigDecimal class in Java?
a) To handle complex numbers
b) To perform precise decimal calculations
c) To save memory
d) To simplify unit tests

A

b) To perform precise decimal calculations

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

What Java method rounds floating point numbers to the closest neighbor?
a) Math.round()
b) RoundingMode.HALF_UP
c) BigDecimal.add()
d) RoundingMode.CEILING

A

b) RoundingMode.HALF_UP

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

What is the purpose of the RoundingMode class in Java?
a) It converts integers to floats
b) It controls rounding behavior for BigDecimal
c) It increases float precision
d) It calculates square roots

A

b) It controls rounding behavior for BigDecimal

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

What is the default rounding mode for BigDecimal in Java?
a) UP
b) DOWN
c) HALF_UP
d) FLOOR

A

c) HALF_UP

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

What does the Java RoundingMode.CEILING setting do?
a) Rounds toward zero
b) Rounds toward positive infinity
c) Rounds toward negative infinity
d) Does not round

A

b) Rounds toward positive infinity

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

What does the RoundingMode.FLOOR setting do?
a) Rounds toward positive infinity
b) Rounds toward zero
c) Rounds toward negative infinity
d) Does not round

A

c) Rounds toward negative infinity

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

What is an advantage of using BigDecimal for financial calculations?
a) It is faster than double
b) It avoids floating point approximation errors
c) It uses less memory
d) It automatically formats currency

A

b) It avoids floating point approximation errors

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

What Java method is used to add BigDecimal numbers?
a) BigDecimal.add()
b) BigDecimal.plus()
c) BigDecimal.sum()
d) Math.addExact()

A

a) BigDecimal.add()

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

What type of result does Math.pow() return?
a) int
b) double
c) float
d) BigDecimal

A

b) double

17
Q

How can we show the result of a division with only three decimal points in Java?
a) Use println with decimals
b) Use printf with %1.3f
c) Use DecimalFormat.setScale()
d) Use format() without decimals

A

b) Use printf with %1.3f

18
Q

What does %f represent in a printf statement in Java?
a) A decimal integer variable
b) A floating point variable
c) A string variable
d) A boolean variable

A

b) A floating point variable

19
Q

Which formatting option in printf creates a new line?
a) %b
b) %d
c) %n
d) %t

A

c) %n

20
Q

In printf, what does %s represent?
a) A string variable
b) A floating point variable
c) A boolean variable
d) A date/time variable

A

a) A string variable

21
Q

Which placeholder in printf is used to format Boolean variables?
a) %f
b) %b
c) %c
d) %d

A

b) %b

22
Q

What is a benefit of using printf over println in formatting output?
a) printf is more accurate
b) printf allows custom precision for floating points
c) printf can only print integers
d) printf does not need a newline character

A

b) printf allows custom precision for floating points

23
Q

Which class in Java allows custom formatting for floating point values?
a) DecimalFormat
b) BigDecimal
c) StringFormat
d) FloatFormat

A

a) DecimalFormat

24
Q

What does DecimalFormat(“#,###.###”) do in Java?
a) Adds thousand separators and restricts to three decimal places
b) Rounds to the nearest integer
c) Formats as a percentage
d) Adds a dollar sign to the output

A

a) Adds thousand separators and restricts to three decimal places

25
Q

Which method is used in Java to calculate the square root of a number?
a) Math.sqrt()
b) Math.square()
c) Math.cbrt()
d) Math.pow()

A

a) Math.sqrt()

26
Q

What is the result of calling Math.cbrt(27) in Java?
a) 3
b) 9
c) 4
d) 27

A

a) 3

27
Q

What does Math.abs(-5.7) return?
a) -5.7
b) 0
c) 5.7
d) -6

A

c) 5.7

28
Q

What will ‘System.out.println(0.1f == 0.1d)’ print in Java?
a) true
b) false
c) 0.1
d) 0.1f

A

b) false

29
Q

What will ‘System.out.printf("%1.1f", 3.456)’ print?
a) 3.5
b) 3.4
c) 3.46
d) 3.5

A

b) 3.5

30
Q

In floating point arithmetic, why is 0.1 not exactly represented in binary?
a) It has a prime factor of 3
b) It is a non-terminating fraction in binary
c) It has a factor of 7
d) It only uses base-10

A

b) It is a non-terminating fraction in binary

31
Q

What does ‘System.out.printf("%1.3f", 5.234567)’ display?
a) 5.23
b) 5.235
c) 5.2
d) 5.24

A

b) 5.235

32
Q

What does Math.pow(5, 2) calculate?
a) 25
b) 10
c) 5
d) 7

A

a) 25

33
Q

What is the effect of using Math.abs() on a negative number?
a) It squares the number
b) It makes the number positive
c) It doubles the number
d) It subtracts 1

A

b) It makes the number positive

34
Q

What does RoundingMode.HALF_DOWN do?
a) Rounds toward positive infinity
b) Rounds to the closest neighbor; rounds down if in between
c) Rounds toward zero
d) Rounds toward negative infinity

A

b) Rounds to the closest neighbor; rounds down if in between

35
Q

What type does Math.cbrt() return?
a) int
b) double
c) float
d) BigDecimal

A

b) double

36
Q

What is the result of calling ‘System.out.printf("%1.1f", 7.89)’?
a) 7.9
b) 7.8
c) 8.0
d) 7.89

A

a) 7.9

37
Q

What method would you use to calculate 5 raised to the power of 3.1 in Java?
a) Math.sqrt()
b) Math.pow()
c) Math.exp()
d) Math.cbrt()

A

b) Math.pow()