Advertisement
yovkovbpfps

Nested LOOPS FISHING

Apr 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Fishing {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int n = Integer.parseInt(scanner.nextLine());
  10.  
  11. double profit = 0;
  12. double cost = 0;
  13. int count = 0;
  14.  
  15. while (true) {
  16.  
  17.  
  18. String f = scanner.nextLine();
  19. if ("Stop".equals(f)) {
  20. if (profit > cost) {
  21. System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", count, profit - cost);
  22. } else {
  23. System.out.printf("Lyubo lost %.2f leva today.", cost - profit);
  24. }
  25. return;
  26. }
  27.  
  28. count++;
  29.  
  30. String q = scanner.nextLine();
  31. for (int k = 0; k <= f.length() - 1; k++) {
  32.  
  33. if (count % 3 == 0) {
  34. profit += (f.charAt(k) / Double.parseDouble(q));
  35. } else {
  36. cost += (f.charAt(k) / Double.parseDouble(q));
  37. }
  38. }
  39.  
  40. if (count == n ) {
  41. break;
  42. }
  43.  
  44. }
  45.  
  46. System.out.println("Lyubo fulfilled the quota!");
  47. if (profit > cost) {
  48. System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", count, profit - cost);
  49. } else {
  50. System.out.printf("Lyubo lost %.2f leva today.", cost - profit);
  51. }
  52.  
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement