Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Java » Programs » Find power

Java program to find power of any number

public class PowerConcept {

	public static void main(String[] args) {
		// power concept --> 2^3 = 8
		int base = 2;
		int exponent = 3;
		
		// 1. method
		long result = 1;
		
		while(exponent != 0) {
			result *= base; // result * base
			--exponent;
		}
		System.out.println(result);
		
		// 2. Method
		//System.out.println(Math.pow(base, exponent));
	}
}