Deep Hypnosis
Deep Hypnosis

Reputation: 17

I am getting two errors while compiling this java code

So i am getting these two errors. 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;
        test[counter]=x;
        System.out.println(test[counter]);

    }

        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;
if(test[level]>0){
    for(int jass=0;jass<(1-level);jass++){
        double test2[];
        double test2[jass]=test[jass];
        System.out.println("level after "+ test2[jass]);
    }

}
 else{
        System.out.println("not less");
    }

enter image description here

Still Nothing happens loop doesn't work. double bucky[]= {50,40,30,20}; double test[]= {0,0,0,0};

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

        int x= (int) c;
        test[counter]=x;
        System.out.println(test[counter]);

    }

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

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

int level=2;
if(test[level]>0){
    double test2[] = new double[test.length];
    for(int jass=0;jass<(1-level);jass++){

         test2[jass]=test[jass];
        System.out.println("level after "+ test2[jass]);
    }

}
 else{
        System.out.println("not less");
    }

Upvotes: 0

Views: 38

Answers (1)

David
David

Reputation: 218798

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]);
}

Upvotes: 1

Related Questions