Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: java application that calculates an exponential function

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java application that calculates an exponential function

    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:

    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
    Why is it an illegal start of an expression? I didn't think you needed to used if statements for a whileloop.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java application that calculates an exponential function

    You should wrap the error message in code tags to preserve formatting (keep the ^ beneath the error)

    Java does not have a ** operator. Look at the Math class for methods to do that operation.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java application for infinite series that calculates pi
    By noblegas in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 6th, 2014, 04:49 PM
  2. Exponential function giving different results
    By Rini in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 14th, 2013, 09:20 PM
  3. Replies: 2
    Last Post: September 27th, 2013, 04:20 AM
  4. Find a java program that calculates
    By Zuhairi Abdullah in forum Object Oriented Programming
    Replies: 3
    Last Post: May 9th, 2013, 11:08 AM
  5. Scientific exponential notation
    By JavaCup in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 9th, 2012, 12:39 AM