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 add java_home in mac 
Java :: java format money 
Java :: java button 
Java :: coding collections clear method java 
Java :: How to chage font progrmatically 
Java :: gradle require java version 
Java :: change text color in joptionpane 
Java :: how to import jframe in java 
Java :: last day of month from localdate java 
Java :: how to declare list of object in java as constant 
Java :: file to image javafx 
Java :: How to create a union-find data structure, in Java? 
Java :: spigot execute command as player 
Java :: How to convert timestamp to time in java 
Java :: change java version maven 
Java :: generate a random phone number in java 
Java :: Private properties in JavaScript ES6 classes 
Java :: no main manifest attribute java 
Java :: json date format for localdate java 
Java :: java how to print 
Java :: how to print multiple lines in java 
Java :: android studio portrait modeeee 
Java :: how to import cert from browser into java 
Java :: java sort list 
Java :: java game 
Java :: sort list of strings java 
Java :: java launch exe 
Java :: how to get multiple integer input in java 
Java :: sorting the characters of a string in java 
Java :: bufferedinputstream to byte array 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =