0
I’m having a question:
The code is as follows::
package yan.exercises.java.struct.repeat;
import java.util.Scanner;
public class exe2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double popA;
double popB;
double taxA;
double taxB;
boolean validate = false;
while (validate = true) {
System.out.print("Enter the population of city A: ");
popA = scan.nextDouble();
if (popA > 0) {
break;
} else {
System.out.println("Population city A need to be bigger than 0.");
}
}
while (validate = true) {
System.out.print("Enter the population of city B: ");
popB = scan.nextDouble();
if (popB > 0) {
break;
} else {
System.out.println("Population city B need to be bigger than 0.");
}
}
while (validate = true) {
System.out.print("Enter the growth rate of A: ");
taxA = scan.nextDouble();
if (taxA > 0) {
break;
} else {
System.out.println("Growth rate city A need to be bigger than 0.");
}
}
while (validate = true) {
System.out.print("Enter the growth rate of B: ");
taxB = scan.nextDouble();
if (taxB > 0) {
break;
} else {
System.out.println("Growth rate city B need to be bigger than 0.");
}
}
int count = 0;
while (popA < popB) {
popA += (popA / 100) * taxA;
popB += (popB / 100) * taxB;
count++;
}
System.out.println("Population A: " + popA);
System.out.println("Population B: " + popB);
System.out.println("Years: " + count);
}
}
You are returning to me the following errors:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The local variable popA may not have been initialized
The local variable popB may not have been initialized
.....
How do I solve this problem? When I start the variable with 0, I get a return, but the program does not return the desired result.
Thanks!! I was really trying to remember the use while(true)!
– hiyan