There is an error in my code that pops when I tried to execute my java application for an exponent function that I wrote. Here is my code and here is the error is generated when I run my code:
//a java application that calculates the power of an integer in a method that the user creates //and uses a while loop to do so. User cannot use any Math class methods to perform this calculation import java.util.Scanner; public class exponentiation{ //main method begins execution of java application public static void main(String[] args){ int base; //declaration for base of exponent int power;//declaration for the power of the exponent int counter=1;//declares and initializes counter for while loop int exponent;//declares exponent function that will be used in the while loop Scanner input=new Scanner(System.in); System.out.println("Entered the base for exponent function:"); base=input.nextInt(); System.out.println("Entered the power for exponent function:"); power=input.nextInt(); System.out.printf("The value of the exponent function is %d", integerPower(base,power)); }//end main method //begin method integerPower that calculates the exponent funtion public static int integerPower(int base,int power){ while(power>=counter){ power=power+counter; exponent=base**power; }//end while loop return exponent; }// end method integerPower }//end class exponentiation
Here is the error that is generated:
Why is it an illegal start of an expression? I didn't think you needed to used if statements for a whileloop.C:\Users\.......\Desktop\chapter 6 java excercises\exponentiation.java:37: error: illegal start of expression
exponent=base**power;
^
1 error
Tool completed with exit code 1