DEPARTMENT OF COMPUTERSCIENCE AND ENGINEERING 23CSR306 – JAVA PROGRAMMING
Ex no: 3
CALCULATING THE POWER
Date:
Question
Create a new class called “Calculator” which contains the following:
• A static method called powerInt(int num1,int num2) that accepts
two integers and
• returns num1 to the power of num2 (num1 power num2).
• A static method called powerDouble(double num1,int num2) that
accepts one double and one integer and returns num1 to the power
of num2 (num1 power num2).
• Call your method from another class without instantiating the class
(i.e. call it like [Link](12,10) since your methods are
defined to be static) Hint: Use [Link](double,double) to
calculate the power.
Aim
To Write a program to perform add and sub using switch case and scanner class.
Code
public class Calculator {
public static int powerInt(int num1, int num2) {
return (int) [Link](num1, num2);
}
public static double powerDouble(double num1, int num2) {
return [Link](num1, num2);
}
public static void main(String[] args) {
[Link]("powerInt(2, 3) = " + [Link](2, 3));
[Link]("powerDouble(2.5, 3) = " + [Link](2.5, 3));
}
}
5 717823P149
DEPARTMENT OF COMPUTERSCIENCE AND ENGINEERING 23CSR306 – JAVA PROGRAMMING
Output
Result
Thus, the Java program for the given relationship has been successfully developed and the
output was verified.
6 717823P149