我正在努力做得更好,所以我从这里开始。
问题是当我尝试使用else
进行测试时,它无法打印。程序到此结束。
有人知道为什么吗?
import java.util.Scanner;
public class CuentaBancaria
{
public static void main(String args[])
{
double EstatusDelBalance = 0.00, Balance = 0.00, Deposito = 0.00, Retiro = 0.00;
Scanner vgd = new Scanner(System.in);
System.out.println("Tu balance actual es: 0");
{
if (EstatusDelBalance <= Balance)
{
System.out.println("\nCuanto desea depositar? ");
Deposito = vgd.nextDouble();
Balance = Deposito + Balance;
System.out.println("\nCuanto desea retirar? ");
Retiro = vgd.nextDouble();
Balance = Balance-Retiro;
EstatusDelBalance = Balance;
}
else
{
System.out.print("No hay balance suficiente para el retiro");
}
}
}
}
答案 0 :(得分:3)
0.0
是Balance
,0.0
是EstatusDelBalance <= Balance
,所以class Submission extends Model
{
public function items()
{
return $this->belongsToMany('App\Item')->withPivot('amount');
}
}
class Item extends Model
{
public function Submissions()
{
return $this->belongsToMany('App\Submission')->withPivot('amount');
}
}
将始终为真。您可能要使用while loop
来解决此问题。
答案 1 :(得分:0)
否则将永远不会打印else,因为EstatusDelBalance
= Balance
。否则,只有在EstatusDelBalance
> Balance
时才打印。
但是我想您会丢失某些内容,因为这里还有多余的{}
,这些多余的 import java.util.Scanner;
public class CuentaBancaria
{
public static void main(String args[])
{
double EstatusDelBalance = 0.00, Balance = 0.00, Deposito = 0.00, Retiro = 0.00;
Scanner vgd = new Scanner(System.in);
System.out.println("Tu balance actual es: 0");
??? -> {
if (EstatusDelBalance <= Balance)
{
System.out.println("\nCuanto desea depositar? ");
Deposito = vgd.nextDouble();
Balance = Deposito + Balance;
System.out.println("\nCuanto desea retirar? ");
Retiro = vgd.nextDouble();
Balance = Balance-Retiro;
EstatusDelBalance = Balance;
}
else
{
System.out.print("No hay balance suficiente para el retiro");
}
??? -> }
}
}
是不必要的(但是如果有循环,则是必需的)……在'???'行中。
@{ Html.RenderAction("ViewCategory", "Books",
new {param1 = "value1", param2 = "value2" }); }
答案 2 :(得分:0)
如果要使else块可执行,请检查一下。我想这就是您所期望的。
import java.util.Scanner;
public class CuentaBancaria
{
public static void main(String args[])
{
double EstatusDelBalance = 0.00, Balance = 0.00, Deposito = 0.00, Retiro = 0.00;
Scanner vgd = new Scanner(System.in);
System.out.println("Tu balance actual es: 0");
System.out.println("\nCuanto desea depositar? ");
{
Deposito = vgd.nextDouble();
Balance = Deposito + Balance;
System.out.println("\nCuanto desea retirar? ");
Retiro = vgd.nextDouble();
Balance = Balance-Retiro;
if (EstatusDelBalance <= Balance)
{
EstatusDelBalance = Balance;
}
else
{
System.out.print("No hay balance suficiente para el retiro");
}
}
}
}