desislava_topuzakova

Untitled

Feb 22nd, 2022
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package Exam;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Fourth {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int computers = Integer.parseInt(scanner.nextLine());
  10. double sales = 0;
  11. double avgPercent = 0;
  12. for(int i = 1 ; i <= computers; i++){
  13. int number = Integer.parseInt(scanner.nextLine());
  14. int lastDigit = number % 10;
  15. int remainingDigits = number / 10;
  16. double percents = 0;
  17. if(lastDigit == 2){
  18. percents = 0;
  19. }else if(lastDigit == 3){
  20. percents = 50;
  21. }else if(lastDigit == 4){
  22. percents = 70;
  23. }else if(lastDigit == 5){
  24. percents = 85;
  25. } else if (lastDigit == 6){
  26. percents = 100;
  27. }
  28. sales += remainingDigits * (percents / 100);
  29. avgPercent += lastDigit;
  30. }
  31. avgPercent = avgPercent / computers;
  32. System.out.printf("%.2f%n",sales);
  33. System.out.printf("%.2f",avgPercent);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment