Java Numbers & Math Class Quiz
35 deep-dive questions on Java's numerical capabilities, from Math utilities and rounding behavior to BigInteger/BigDecimal precision, number formatting, and the subtle dangers of primitive overflow.
Question 1
What is the output of Math.abs(Integer.MIN_VALUE)?
Question 2
What is the result?
System.out.println(0.1 + 0.2 == 0.3);Question 3
Which Math method rounds 3.6 to the nearest integer toward positive infinity?
Question 4
What is printed?
BigDecimal a = new BigDecimal("0.1");
BigDecimal b = new BigDecimal("0.2");
System.out.println(a.add(b));Question 5
What is the output?
System.out.println(Math.floor(-3.2));Question 6
Which class should be used for exact decimal arithmetic (e.g., money)?
Question 7
What is the result?
long x = Integer.MAX_VALUE + 1L;
System.out.println(x);Question 8
What is printed?
System.out.println(Math.pow(2, 3));Question 9
What is the output?
BigInteger a = BigInteger.valueOf(1000);
BigInteger b = a.multiply(BigInteger.TEN);
System.out.println(b);Question 10
Which method returns a pseudorandom double greater than or equal to 0.0 and less than 1.0?
Question 11
What is the result?
int x = 1000000;
int y = 1000000;
int z = x * y;
System.out.println(z);Question 12
What is printed?
System.out.printf("%.2f", 123.45678);Question 13
Which of these is the safest way to detect potential overflow before multiplication?
Question 14
What is the output?
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println(nf.format(1234.56));Question 15
What is the result?
BigDecimal value = BigDecimal.valueOf(0.1);
value = value.add(BigDecimal.valueOf(0.2));
System.out.println(value);Question 16
What does Math.nextUp(0.0) return?
Question 17
What is printed?
System.out.println(Math.round(3.5));
System.out.println(Math.round(-3.5));Question 18
Which pattern formats 1234.567 as '1,234.57'?
Question 19
What is the safest way to convert String to BigDecimal?
Question 20
What is printed?
Random r = new Random(12345);
System.out.println(r.nextInt(10) == r.nextInt(10));Question 21
Which of these values can be exactly represented in double?
Question 22
What is the result of Math.addExact on overflow?
Question 23
What is printed?
DecimalFormat df = new DecimalFormat("0000.00");
System.out.println(df.format(123.4));Question 24
Why is 2,147,483,647 + 1 equal to -2,147,483,648 in int arithmetic?
Question 25
What is the output?
System.out.println(Math.min(-0.0, 0.0) == -0.0);Question 26
Which method should be used to generate cryptographically secure random numbers?
Question 27
What is printed?
BigDecimal bd = new BigDecimal("10.0");
bd = bd.stripTrailingZeros();
System.out.println(bd.toPlainString());Question 28
What is the result of Integer.parseInt("123456789012345")?
Question 29
What is printed?
System.out.println(Math.toDegrees(Math.PI));Question 30
Which of these is NOT a method in java.lang.Math?
Question 31
What is the most important lesson about numeric computation in Java?
Question 32
What is printed?
double d = 1.0 / 0.0;
System.out.println(d);Question 33
What is the result?
System.out.println(Double.isNaN(Math.sqrt(-1)));Question 34
Why is ThreadLocalRandom preferred in multithreaded applications?
Question 35
After completing this quiz, you now understand that:
