Deep Hypnosis Deep Hypnosis - 2 years ago 97
Java Question

I am getting two errors while compiling this java code

so i am getting these two errorsenter image description here. How can I solve them? and one more thing can anyone give me short code for variable c.

double bucky[]= {7.8,5.9,4.1};
double test[]= {0,0,0};

for(int counter=0;counter<bucky.length;counter++){
double c=(12-(test[0]*bucky[0]+test[1]*bucky[1]+test[2]*bucky[2]))/bucky[counter];

int x= (int) c;


double summation=test[0]*bucky[0]+test[1]*bucky[1]+test[2]*bucky[2];

double loss=12-summation;
System.out.println("Loss is "+ loss);

int level=2;
for(int jass=0;jass<(1-level);jass++){
double test2[];
double test2[jass]=test[jass];
System.out.println("level after "+ test2[jass]);

System.out.println("not less");

Answer Source

The syntax for declaring and using an array would be something like:

double[] test2 = new double[someLengthValue];
test2[someIndex] = someValue;

But the whole thing is kind of moot, really. In your loop you re-declare a new array every iteration and try to set a single value in that array. Then all you do is print that value. You don't need that array at all:

for(int jass=0;jass<(1-level);jass++){
    System.out.println("level after "+ test[jass]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download