Question 13
Consider the Java code given below.
You may make use of the description given below.
The logarithm of a number n to the base x is the number of times x has to be multiplied with itself so get n, and is denoted by .
For example, , . Note that .
class Logarithm{ private int base; // Constructor to initialize the instance variable base public int log(int num) { assert num > 0; //LINE 1 if (num == 1) return 0; assert base > 0; //LINE 2 return 1 + log(num/base); } } public class AssertionTest { public static void main(String[] args) { Logarithm obj1 = new Logarithm(10); Logarithm obj2 = new Logarithm(-2);
System.out.println(obj1.log(1000)); System.out.println(obj2.log(-2)); } }Choose the correct option when the program is executed as:
java -ea AssertionTest