Multiplying Variables

• 12-03-2009, 07:47 AM
rnavarro9
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);
• 12-03-2009, 08:14 AM
pbrockway2
What is the compiler message?

You don't usually have statements like that outside a method or constructor.
• 12-03-2009, 08:19 AM
rnavarro9
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);

}
• 12-03-2009, 08:32 AM
rnavarro9
That definitely isn't the problem.
• 12-03-2009, 09:10 AM
JosAH
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