# Thread: Multiplying Variables

1. Member
Join Date
Nov 2007
Posts
7
Rep Power
0

## 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. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14
What is the compiler message?

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

3. Member
Join Date
Nov 2007
Posts
7
Rep Power
0
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. Member
Join Date
Nov 2007
Posts
7
Rep Power
0
That definitely isn't the problem.
Last edited by rnavarro9; 12-03-2009 at 08:33 AM. Reason: Need Link

5. 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

#### Posting Permissions

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