Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have been trying to work on this code to calculate polynomials for a while, but it seems I am stuck due to my low knowledge of java

Java
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:

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(x1)?");
				int x2 = readInteger("Please enter the value of x2:");
				polynom pol2 = new polynom (m,n,0,x2);


I would be very thankful for any help :)

What I have tried:

I tried not to use the if statements, but I get as a print of f(x1) and f(x2) with the first given power and then get 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.
Posted
Updated 30-May-18 3:15am

1 solution

Java
if (x1>=0 || x1<0) {

Translation:
IF x1 is greater than or equal to 0
OR x1 is less than 0

i.e if x1 is any value ...

Same for x2 further down. So those tests do nothing, and it is not clear what is not working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900