I don't understand why if (isSolution==true) or if (isSolution = true) cannot be a legal start of a if statement as the isSolution was declared and assigned false. Logically, it makes sense, but I don't understand how to work out the syntax. Java Code: import java.util.Scanner; public class LabProgram { public static void main(String[] args) { /* Type your code here. */Scanner scnr= new Scanner(System.in); int x1=scnr.nextInt(); int y1=scnr.nextInt(); int z1=scnr.nextInt(); int x2=scnr.nextInt(); int y2=scnr.nextInt(); int z2=scnr.nextInt(); int x=0; int y=0; Boolean isSolution=false; for (int i= -10; i < 11; i++) { for (int j= -10; i < 11; j++) { if ((x1 * i + y1 * j == z1) && (x2 * i + y2 * j == z2)) isSolution = true; x=i; y=j; break; } } } if (isSolution==true) { System.out.println("x= " +x+ "y= " +y); } else { System.out.println("There is no solution"); } }
I don't understand why if (isSolution==true) or if (isSolution = true) cannot be a legal start of a if statement as the isSolution was declared and assigned false. Logically, it makes sense, but I don't understand how to work out the syntax.
Java Code:
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
/* Type your code here. */Scanner scnr= new Scanner(System.in);
int x1=scnr.nextInt();
int y1=scnr.nextInt();
int z1=scnr.nextInt();
int x2=scnr.nextInt();
int y2=scnr.nextInt();
int z2=scnr.nextInt();
int x=0;
int y=0;
Boolean isSolution=false;
for (int i= -10; i < 11; i++) {
for (int j= -10; i < 11; j++) {
if ((x1 * i + y1 * j == z1) && (x2 * i + y2 * j == z2))
isSolution = true;
x=i;
y=j;
break;
}
}
}
if (isSolution==true) {
System.out.println("x= " +x+ "y= " +y);
} else {
System.out.println("There is no solution");
}
}
Step by step
Solved in 2 steps