galinyotsev123

ProgBasics05while-Loop-P06accountBalance

Jan 7th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P06accountBalance {
  4. public static void main(String[] args) {
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7. {
  8.  
  9. int n = Integer.parseInt(scanner.nextLine());
  10.  
  11. int counter = 0;
  12.  
  13. double balance = 0.0;
  14.  
  15. while (counter < n) {
  16.  
  17. double amount = Double.parseDouble(scanner.nextLine());
  18.  
  19. if (amount < 0) {
  20.  
  21. System.out.println("Invalid operation!");
  22. break;
  23.  
  24. }
  25.  
  26. balance += amount;
  27.  
  28. System.out.printf("Increase: %.2f%n", amount);
  29.  
  30. counter++;
  31.  
  32.  
  33.  
  34. }System.out.printf("Total: %.2f", balance);
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment