mercredi 30 mai 2018

executing these two codes after each other with an if statement

if (m>1){

        if (x1>=0 || x1<0) {
            System.out.println("Please enter the values of f(x1): \n");
            for (int i = Koef.length-2; i >=0; i--) { // gives the length of my row (m)
                for (int j =Koef[0].length-1; j>=0;j--) { //gives the length of my column (n).
                    Koef[0][j] = readInteger("Enter the values of your coeffecients: "
                                            +"f(x1), Coeffecient" +(j)+": "); // readInteger takes an input from the user
                }
                    System.out.println();
            }
        }

//MY PROBLEM is here
//I was trying to execute this code below too after the code above finishes, but somehow it never reaches to it

        if(x2>=0 || x2<0) {
            System.out.println("Now enter the value of f(x2):  \n");
            for (int i = Koef.length-2; i >=0; i--) { 
                for (int j =Koef[0].length-1; j>=0;j--) { 

                    Koef[1][j] = readInteger("Enter the value of coefficients: "
                                            +"f(x2), Coefficient" +(j)+": ");
                }
            }
        }
====================================================================

//This what happens in the testClass:

if (m==2) {
int n = 1+readInteger("Which polynomial degree do you want to enter for f(x1)?");
                int x1 = readInteger("please enter the value of x1:");
                polynom pol1 = new polynom (m,n,x1,0); //m-2 = array 0 & n +1 = polynomial degree of array 0

// m is first array, n is second array, x1 is the value of 1st polynomial x2 value of 2nd

int n = 1+readInteger("Which polynomial degree do you want to enter for f(x2)?");
                int x2 = readInteger("Please enter the value of x2:");
                polynom pol2 = new polynom (m,n,0,x2);
}

I already tried not to use the if statements, but I got as a print of f(x1) and f(x2) with the first given power and then got both results again with the 2nd given power.

What I want is: to get f(x1) with the first power (n) and f(x2) with the second power Each, one time only.

I would be grateful if you can get me out of this predicament Thanks for any help :)

Aucun commentaire:

Enregistrer un commentaire