Q:

Java Program To Calculate Power Of Number by taking user input

0

Program To Calculate Power Of Number by taking user input.

All Answers

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

import java.util.Scanner;
public class demo1
{
   public static void main(String arg[])	
    {	
       long a,b,r=1;	
       Scanner input=new Scanner(System.in); 
       System.out.println("enter number");	  
       a=input.nextLong();
       System.out.println("enter power");	  
       b=input.nextLong();
       if(a>=0&&b==0)
       {   
          r =1;
       }
       else if(a==0&&b>=1)
	{   
            r=0;
	} 
       else
	{ 
              for(int i=1;i<=b;i++)
	       { 
                   r=r *a;
 	 	}    
  	 }     
    	  System.out.println(a+"^"+b+"="+r);
    }
 
}

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