package piggybank;
import java.util.Scanner;
public class piggybank
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Welcome to the Piggy Bank. Please enter starting balance: ");
double startingBalance = input.nextDouble();
System.out.println("Piggy Bank ATM");
System.out.printf("Balance : %6.2f", startingBalance);
System.out.println();
while (true){
System.out.println();
System.out.println("OPTIONS");
System.out.println();
System.out.println("1.Deposit\n"+"2.Withdraw\n"+"3.Quit\n");
System.out.println();
System.out.println("Choose one:");
int option = input.nextInt();
switch (option) {
case 1:
System.out.println("Enter deposit amount:\n" + "Piggy Bank ATM");
double deposit = input.nextDouble();
double depositBalance= startingBalance + deposit;
System.out.printf(" Balance: $%6.2f ",depositBalance);
System.out.println();
break;
case 2:
System.out.println("Enter withdrawal amount:\n" + "Piggy Bank ATM");
double withdraw = input.nextDouble();
double withdrawBalance= startingBalance - withdraw;
System.out.printf("Balance:$%8.2f ",withdrawBalance);
System.out.println();
break;
case 3:
System.out.printf("Ending Balance: $%8.2f ", startingBalance);
break;
}
input.close();
}
}
}
我想要反复执行存取款程序,但是就会显示出错
求帮忙!
想要得到以下运行结果
我的运行结果是这样的,没有办法进行第二次输入
呜呜呜,初学什么都不会,求助