Java

Math

Integer Max

public class Program {
public static void main(String[] args) {
*// Raise 5 to the power of 2.*
*// ... Then raise 3 to the power of 2.*
double result1 = Math.pow(5, 2);
double result2 = Math.pow(3, 2);
*// ... Display our results.*
System.out.println(result1);
System.out.println(result2);
}
}25.0
9.0

Method

public class Program {
static double square(int base) {
*// We use Math.pow with a second argument of 2 to square.*
return Math.pow(base, 2);
}
public static void main(String[] args) {
*// Use square method.*
double result1 = square(2);
double result2 = square(3);
double result3 = square(4);
System.out.println(result1);
System.out.println(result2);
System.out.println(result3);
}
}4.0
9.0
16.0

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

No updates found for this page.