Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

find power of number in method java

package javaprogramms;
import java.util.Scanner;


public class powermethod {
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	
	System.out.println("Enter Base Number: ");
	int base=sc.nextInt();
	System.out.println("Enter Power Number: ");
	int pw=sc.nextInt();
	
	power(base,pw);
}
public static void power(int base, int pw) {
	int res=1;
	while(pw>0) {
		res=res*base;
		pw--;
	}
	System.out.println("Result: "+res);
}
}
 
PREVIOUS NEXT
Tagged: #find #power #number #method #java
ADD COMMENT
Topic
Name
8+1 =