Results 1 to 5 of 5
  1. #1
    rnavarro9 is offline Member
    Join Date
    Nov 2007
    Posts
    7
    Rep Power
    0

    Exclamation Multiplying Variables

    Hello Everyone,

    I'm currently using Eclipse IDE and I'm encountering an error on my variable declaration line after I type the third line

    import java.math.*;
    .
    .
    .
    .
    .
    double constant, energyConstant, transRange;
    energyConstant = constant * Math.pow(transRange,2);
    Last edited by rnavarro9; 12-03-2009 at 07:59 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    What is the compiler message?

    You don't usually have statements like that outside a method or constructor.

  3. #3
    rnavarro9 is offline Member
    Join Date
    Nov 2007
    Posts
    7
    Rep Power
    0

    Default

    Error: Syntax error on token ";", , expected

    I'll evntually refactor those lines into methods.
    Here is my whole code:


    import java.math.*;

    public class sensorNode {


    private int xCoordinate;
    private int yCoordinate;
    private double energyLevel;

    /**
    * @param xInit the x-coordinate for node
    * @param yInit the y-coordinate for node
    * @param newEnergy the initial energy for node
    */
    public sensorNode(int xInit, int yInit, double newEnergy){

    xCoordinate = xInit;
    yCoordinate = yInit;
    energyLevel = newEnergy;
    }

    double konstant = 0 ;
    double energyConstant = 0;
    double transRange = 0;

    energyConstant = konstant * Math.pow(transRange,2);

    }

  4. #4
    rnavarro9 is offline Member
    Join Date
    Nov 2007
    Posts
    7
    Rep Power
    0

    Default

    That definitely isn't the problem.
    Last edited by rnavarro9; 12-03-2009 at 08:33 AM. Reason: Need Link

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default

    Java Code:
    import java.math.*;
    
    public class sensorNode {
    
    	
    	private int xCoordinate;
    	private	int yCoordinate;
    	private	double energyLevel;	
    	
    	/**
    	 * @param xInit the x-coordinate for node
    	 * @param yInit the y-coordinate for node
    	 * @param newEnergy the initial energy for node
    	 */
    	public  sensorNode(int xInit, int yInit, double newEnergy){
    		
    		xCoordinate = xInit;
    		yCoordinate = yInit;
    		energyLevel = newEnergy;
    	}
    
    	double konstant = 0 ;
    	double energyConstant = 0;
    	double transRange = 0;
    
    // ordinary statements are not allowed outside method bodies
    	energyConstant = konstant * Math.pow(transRange,2);
    	
    }
    kind regards,

    Jos

Similar Threads

  1. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 06:48 PM
  2. [SOLVED] Multiplying Objects Problme
    By thelinuxguy in forum Advanced Java
    Replies: 7
    Last Post: 05-07-2009, 06:19 PM
  3. Declaring variables
    By Flashmatix in forum New To Java
    Replies: 12
    Last Post: 01-20-2009, 04:43 PM
  4. Variables
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 01:44 PM
  5. variables-methods
    By Warren in forum New To Java
    Replies: 1
    Last Post: 11-28-2007, 05:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •