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 :: unable to access jarfile 
Java :: error: package android.support.v7.app does not exist 
Java :: kubectl config kubernetes dashboard 
Java :: android java back button closeapp 
Java :: mono command to compile C# library code 
Java :: set layout params in dp value 
Java :: java swing windows 10 look and feel 
Java :: json array get json object 
Java :: java android development find element by id 
Java :: How to efficiently reverse a singly linked list, in Java? 
Java :: math.min java 
Java :: java date add hours 
Java :: java int array to integer arraylist 
Java :: get list data in java 
Java :: sublist java 
Java :: java 2 decimals 
Java :: sort a list with custom comparator java 
Java :: Create class from string variable JAVA 
Java :: java map create with values 
Java :: convert arraylist to array int 
Java :: java character 
Java :: atm machine java project 
Java :: print symbol in pyramid shape in java 
Java :: how to plus two numbers in java 
Java :: Java Type conversion from String to int 
Java :: exception in thread "main" java.lang.unsupportedclassversionerror: has been compiled by a more recent version of the java runtime (class file version 55.0), this version of the java runtime only recognizes class file versions up to 52.0 
Java :: Java Converting double into an int 
Java :: how to check duplicate string in java 
Java :: what is outer class in java 
Java :: java convert ip to long 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =