Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to find power of a number in java

int powerOfNumber = (int) Math.pow(number, power);
Comment

Java program to find the power of a number

@Test
	public void powerOfTheNumberProgram13() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("Enter any NUMBER: ");
		int number = scanner.nextInt();
		System.out.println("Enter the POWER: ");
		int power = scanner.nextInt();
		scanner.close();
		// Logic for finding the POWER of number
		int powerOfNumber = (int) Math.pow(number, power);
		System.out.println("Power of a " + number + "^" + power + ": " + powerOfNumber);
	}
Comment

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);
}
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to saperate string to array 
Java :: how to set default color in android studio 
Java :: string formatting java 
Java :: java generate random string and number 
Java :: add integers java 
Java :: resultset methods in jdbc 
Java :: string program to calculate number of characters in a string java 
Java :: number of matches regex java 
Java :: update role spring security 
Java :: Java Access HashMap Elements 
Java :: polimorfismo java ejemplo 
Java :: get image from resourcestream javafx 
Java :: android disable inputs while loading 
Java :: java.lang.NoClassDefFoundError: net/sf/cb2xml/def/IItem 
Sql :: delete all nodes neo4j 
Sql :: uninstall mysql ubuntu 
Sql :: guid to string sql 
Sql :: apex execute batch job 
Sql :: Enter into postgresql database,create user and grant Access 
Sql :: refresh postgres config 
Sql :: sql get missing id 
Sql :: sql add year to date 
Sql :: oracle kill session 
Sql :: find mysql version linux 
Sql :: autoincrement sqlite command 
Sql :: VERIFY INDEXES IN SQL ORACLE 
Sql :: mysql allow remote connections 
Sql :: add primary key constraint in oracle 
Sql :: oracle current date without time 
Sql :: convert epoch to date in sql server 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =