Q:

Java Program To Calculate Power Of Number

0

Java Program To Calculate Power Of Number

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[])	
  {
    int a=2,b=4,value=1;
 
    if(a>=0&&b==0)
     {
        value=1;
     }
    else if(a==0&&b>=1)
      { 
         value=0;
      }
    else
     {
         for(int i=1;i<=b;i++)
	 {
            value=value*a;
 	 }	    
     }
    System.out.println(a+"^"+b+"="+value);	
  }
}

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