0% found this document useful (0 votes)
10 views

Java Record 3

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Java Record 3

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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 Calculator.powerInt(12,10) since your methods are
defined to be static) Hint: Use Math.pow(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) Math.pow(num1, num2);
}
public static double powerDouble(double num1, int num2) {
return Math.pow(num1, num2);
}
public static void main(String[] args) {
System.out.println("powerInt(2, 3) = " + Calculator.powerInt(2, 3));
System.out.println("powerDouble(2.5, 3) = " + Calculator.powerDouble(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

You might also like