Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.io.OutputStream;
  2. import java.util.Scanner;
  3.  
  4. public class newnew {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int days = Integer.parseInt(scanner.nextLine());
  9. double allFood = Double.parseDouble(scanner.nextLine());
  10. int dogEat = 0;
  11. int catEat = 0;
  12. int dogEats =0 ;
  13. int catEats = 0;
  14. double biscuitsAll = 0;
  15.  
  16. for (int i = 1; i <= days ; i++) {
  17. dogEat = Integer.parseInt(scanner.nextLine());
  18. catEat = Integer.parseInt(scanner.nextLine());
  19. dogEats = dogEats + dogEat;
  20. catEats = catEats + catEat;
  21.  
  22. if(i % 3 == 0){
  23. double earn = Math.ceil( 0.1 *( dogEats + catEats ));
  24. biscuitsAll = biscuitsAll + earn;
  25. }
  26. }
  27. double allEats = catEats + dogEats;
  28. double dogPercent = (dogEats * 1.0) * 100 / allEats;
  29. double catPercent = (catEats * 1.0) * 100 / allEats;
  30. double percentAllFood = allEats * 100 / allFood;
  31. System.out.printf("Total eaten biscuits: %.0fgr.%n", biscuitsAll);
  32. System.out.printf("%.2f%% of the food has been eaten.%n",percentAllFood);
  33. System.out.printf("%.2f%% eaten from the dog.%n",dogPercent);
  34. System.out.printf("%.2f%% eaten from the cat.",catPercent);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement