0% found this document useful (0 votes)
7 views1 page

PGM 2

The document contains a Java class named Calculator with two static methods for calculating powers: one for integers and another for doubles. The main method tests both methods, demonstrating their functionality by calculating 2 raised to the power of 3 and 2.5 raised to the power of 3. The results are printed to the console.

Uploaded by

wasimrajaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

PGM 2

The document contains a Java class named Calculator with two static methods for calculating powers: one for integers and another for doubles. The main method tests both methods, demonstrating their functionality by calculating 2 raised to the power of 3 and 2.5 raised to the power of 3. The results are printed to the console.

Uploaded by

wasimrajaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

public class Calculator {

// Static method for integer power


public static int powerInt(int num1, int num2) {
return (int) Math.pow(num1, num2);
}

// Static method for double power


public static double powerDouble(double num1, int num2) {
return Math.pow(num1, num2);
}

// Main method to test both methods


public static void main(String[] args) {
// Test the powerInt method
int intResult = Calculator.powerInt(2, 3); // 2^3 = 8
System.out.println("powerInt(2, 3) = " + intResult);

// Test the powerDouble method


double doubleResult = Calculator.powerDouble(2.5, 3); // 2.5^3 = 15.625
System.out.println("powerDouble(2.5, 3) = " + doubleResult);
}
}

You might also like