yovkovbpfps

While Loop Account Balance

Apr 3rd, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AccountBalance {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int counter = 1;
  7. double account = 0;
  8. String command = "";
  9.  
  10. int transactions = Integer.parseInt(scanner.nextLine());
  11.  
  12. while (counter <=transactions) {
  13. double money = Double.parseDouble(scanner.nextLine());
  14. if ( money <0) {
  15. System.out.println("Invalid operation!");
  16. break;
  17. }else {
  18. account += money;
  19. System.out.printf("Increase: %.2f%n",money);
  20. }
  21. counter++;
  22. }
  23. System.out.printf("Total: %.2f", account);
  24.  
  25.  
  26.  
  27. }
  28. }
Add Comment
Please, Sign In to add comment