title-img


Java Exception Handling

You are required to compute the power of a number by implementing a calculator. Create a class MyCalculator which consists of a single method long power(int, int). This method takes two integers, n and p, as parameters and finds . If either or is negative, then the method must throw an exception which says "n or p should not be negative". Also, if both n and p are zero, then the method must throw an exception which says "n and p should not be zero" For example, -4 and -5 would result in jav

View Solution →

Java Varargs - Simple Addition

You are given a class Solution and its main method in the editor. Your task is to create the class Add and the required methods so that the code prints the sum of the numbers passed to the function add. Note: Your add method in the Add class must print the sum as given in the Sample Output Input Format There are six lines of input, each containing an integer. Output Format There will be only four lines of output. Each line contains the sum of the integers passed as the parameters

View Solution →

Java Reflection - Attributes

JAVA reflection is a very powerful tool to inspect the attributes of a class in runtime. For example, we can retrieve the list of public fields of a class using getDeclaredMethods(). In this problem, you will be given a class Solution in the editor. You have to fill in the incompleted lines so that it prints all the methods of another class called Student in alphabetical order. We will append your code with the Student class before running it. The Student class looks like this: class Stude

View Solution →

Can You Access? Java

You are given a class Solution and an inner class Inner.Private. The main method of class Solution takes an integer num as input. The powerof2 in class Inner.Private checks whether a number is a power of 2. You have to call the method powerof2 of the class Inner.Private from the main method of the class Solution. Constraints 1<=num<=2^30

View Solution →

Prime Checker Java

You are given a class Solution and its main method in the editor. Your task is to create a class Prime. The class Prime should contain a single method checkPrime. The locked code in the editor will call the checkPrime method with one or more integer arguments. You should write the checkPrime method in such a way that the code prints only the prime numbers. Please read the code given in the editor carefully. Also please do not use method overloading! Note: You may get a compile time erro

View Solution →