如何使用if语句java执行这两个代码 [英] How do I execute this two codes with if statements java
问题描述
我一直在尝试使用这段代码来计算多项式一段时间,但是由于我对java的了解很少,我似乎陷入困境
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
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);
我会非常感谢任何帮助:)
什么我试过了:
我尽量不使用if语句,但我得到了f(x1)的打印)和f(x2)的第一个给定的功率,然后再次获得两个结果与第二给定的功率。
我想要的是:获得f(x1)第一个幂(n)和f(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.
推荐答案
if (x1>=0 || x1<0) {
翻译:
如果x1大于或等于0
或者x1小于0
即如果x1是任何价值......
x2进一步向下相同。所以这些测试什么都不做,而且不清楚什么是无效的。
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.
这篇关于如何使用if语句java执行这两个代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!