desislava_topuzakova

05. Account Balance

Oct 9th, 2021
1,483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //команда -> double или "NoMoreMoney"
  7.         //повтарям: въвеждам команда
  8.         //стоп: команда == "NoMoreMoney"
  9.         //продължавам: команда != "NoMoreMoney"
  10.         double totalSum = 0;
  11.         String command = scanner.nextLine(); //начална стойност на командата
  12.         while(!command.equals("NoMoreMoney")) {
  13.             //command = "5.51" -> дробно число
  14.             double sum = Double.parseDouble(command);
  15.             if(sum < 0) {
  16.                 System.out.println("Invalid operation!");
  17.                 break;
  18.             }
  19.             System.out.printf("Increase: %.2f%n", sum);
  20.             totalSum += sum;
  21.  
  22.             command = scanner.nextLine();
  23.         }
  24.         System.out.printf("Total: %.2f", totalSum);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment