estou com uma dúvida:
O código é o seguinte:
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);
}
}
Está me retornando os seguintes erros:
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
.....
Como consigo resolver este problema? Quando eu inicializo a variável com 0, consigo retorno, mas o programa não me retorna o resultado desejado.