-2
public boolean para () {
return false;
}
public void acao (int acao) {
if (acao == 1) {
System.out.println("Diga quanto quer depositar: ");
Scanner sc = new Scanner (System.in);
double valor = sc.nextDouble();
this.saldo += valor;
}
if (acao == 2) {
System.out.println("Diga quanto quer depositar: ");
Scanner sc = new Scanner (System.in);
double valor = sc.nextDouble();
if (valor > this.saldo) {
System.out.println("Você não tem esse valor");
}else {
this.saldo -= valor;
}
}
if (acao == 3) {
System.out.println("Seu saldo é: " + this.saldo);
}
else {
this.para();
}
}
I created this method to choose which function the program will do, when other than 1,2,3 I wanted to return false to make While (true) stop.
while (true){
System.out.println("Escolha uma função 1- Depositar 2- Sacar 3- Ver Saldo");
int acao = sc.nextInt();
usuario01.acao(acao);
}
Where is the error and pq does not return false?
When you do
this.para, is calling the method, but its return is "lost" (it is not assigned to any variable, nor used anywhere). Anyway, this method (which only returnsfalse) is half useless. To work, an alternative is the methodacaoreturn the boolean whether to continue or not: https://ideone.com/qLnJZW– hkotsubo
got it. very obg
– Arthur Galdino