Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int quota = Integer.parseInt(scanner.nextLine());
- double Save = 0;
- double Spend = 0;
- String fish = scanner.nextLine();
- int counter = 0;
- double diff = 0;
- while (!fish.equals("Stop")) {
- counter++;
- if (counter == quota) {
- System.out.println("Lyubo fulfilled the quota!");
- break;
- }
- double kg = Integer.parseInt(scanner.nextLine());
- if (counter%3 == 0) {
- for (int i = 0; i <= fish.length() - 1; i++) {
- char currentSave = fish.charAt(i);
- Save += currentSave;
- // if (i == fish.length() - 1) {
- Save = Save / kg;
- //}
- }
- }else {
- for (int i = 0; i <= fish.length() - 1; i++) {
- char currentSpend = fish.charAt(i);
- Spend += currentSpend;
- // if (i == fish.length() - 1) {
- Spend = Spend / kg;
- // }
- }
- }
- fish=scanner.nextLine();
- }
- if (Save >= Spend) {
- diff = Math.abs(Spend - Save);
- System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", counter, diff);
- } else {
- diff = Math.abs(Spend - Save);
- System.out.printf("Lyubo lost %.2f leva today.", diff);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement