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 accept only numbers and whitespace in java 
Java :: clor text consol java 
Java :: Remove ArrayList Elements using remove() function 
Java :: Android number format thousands separator 
Java :: Copying value from one input field to another input field using checkbox 
Java :: thread dump 
Java :: primitive vs wrapper classes in java 
Java :: java deserialize json array 
Java :: Declaration of java list 
Java :: the crystallization in time is the phenomenon that we call synchronization 
Java :: jmonkey shapes 
Java :: spring boot dto example java 
Java :: how to switch between two stylesheets in javafx. 
Java :: java nom de la methode actuel 
Java :: Java Labeled continue Statement Java 
Java :: pagina en java 
Java :: open youtube by default in full landscape mode pragmatically 
Java :: java singleton with synchronized 
Java :: youtube converter to mp3 
Java :: android studio call on a string 
Java :: copy array of objects in java 
Java :: What is the difference between Error and Exception? java 
Java :: nbubble sort java 
Java :: lombok boolean is prefix 
Java :: react-native maven package 404 not found 
Java :: start with < and end with < in Java 
Java :: Check if service running in the background 
Java :: how to make a typewriter effect in jaca 
Java :: android studio analyze apk 
Java :: java ordenar numeros ascendente 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =