samedi 30 septembre 2017

loop back to beginning of program Java

I am new to Java, would anybody be able to give me any guidance on how I can get this program to continuously run after user input? Should i use a while loop? Many thanks!

System.out.println("Would you like to deposit or withdraw?");
Scanner user_input = new Scanner (System.in);
String transaction_type;
transaction_type = user_input.next();
String transaction;

 if (transaction_type.equals("withdraw")){
 numberOfWithdrawals++;
 System.out.println(numberOfWithdrawals);
} else if (transaction_type.equals("deposit")){
    numberOfDeposits++;
    System.out.println(numberOfDeposits);
} else if (transaction_type != "withdraw" && transaction_type != "deposit")
{
    System.out.println("Invalid input, please re-enter desired transaction");
    next = sc.nextLine();
}
}

Aucun commentaire:

Enregistrer un commentaire