Q:

write a java program that computes n^p where n and p are two numbers given by the user

0

write a java program that computes np where n and p are two numbers given by the user.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class NewClass {
     public static void main(String args[]) throws Exception
    {
        int n,p;
        Scanner input=new Scanner(System.in);
        System.out.println("enter the basis number n : ");
        n=input.nextInt();
        System.out.println("enter the power number p : ");
        p=input.nextInt();
        int i=1;
        int result=1;
        while(i<=p)
        {
            result=result*n;
            i++;
        }
        System.out.println("result of power is "+result);
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now