Floating point arithmetic Flashcards
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
b) Floating point arithmetic includes decimal precision
What term refers to the degree of correctness in floating point operations?
a) Precision
b) Clarity
c) Accuracy
d) Scope
c) Accuracy
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
c) It introduces approximation due to binary representation
What is the binary representation of the decimal number 0.1?
a) 0.1
b) 0.001
c) 0.000110011001100110011001100110011
d) 0.100000001
c) 0.000110011001100110011001100110011
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
c) Prime factors of decimal and binary systems differ
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
b) They are represented with different numbers of bits
Which Java type allows the most precision for floating point numbers?
a) int
b) double
c) float
d) long
b) double
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
b) To perform precise decimal calculations
What Java method rounds floating point numbers to the closest neighbor?
a) Math.round()
b) RoundingMode.HALF_UP
c) BigDecimal.add()
d) RoundingMode.CEILING
b) RoundingMode.HALF_UP
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
b) It controls rounding behavior for BigDecimal
What is the default rounding mode for BigDecimal in Java?
a) UP
b) DOWN
c) HALF_UP
d) FLOOR
c) HALF_UP
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
b) Rounds toward positive infinity
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
c) Rounds toward negative infinity
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
b) It avoids floating point approximation errors
What Java method is used to add BigDecimal numbers?
a) BigDecimal.add()
b) BigDecimal.plus()
c) BigDecimal.sum()
d) Math.addExact()
a) BigDecimal.add()
What type of result does Math.pow() return?
a) int
b) double
c) float
d) BigDecimal
b) double
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
b) Use printf with %1.3f
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
b) A floating point variable
Which formatting option in printf creates a new line?
a) %b
b) %d
c) %n
d) %t
c) %n
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 string variable
Which placeholder in printf is used to format Boolean variables?
a) %f
b) %b
c) %c
d) %d
b) %b
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
b) printf allows custom precision for floating points
Which class in Java allows custom formatting for floating point values?
a) DecimalFormat
b) BigDecimal
c) StringFormat
d) FloatFormat
a) DecimalFormat
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) Adds thousand separators and restricts to three decimal places