Saturday, September 5, 2020

To write a java program to find the value of a number rose to its power that demonstrates a method using call by value.

 import java.util.Scanner;

 public class power_number

 {

   public static Scanner sayed;

  public static void main(String[] args)

   {

    int base,exp;

    sayed=new Scanner (System.in);

   System.out.println("Enter the number and power:");

    base=sayed.nextInt();

    exp=sayed.nextInt();

    System.out.print(result(base,exp));

    }

   public static double result(int base, int exp)

    {

      System.out.print(""+base+" to the power "+exp+" = ");

      return Math.pow(base,exp); 

    } 

  }

No comments:

Post a Comment