Advertisement
Ivakis

Четни/Нечетни позиции

Aug 26th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class demo {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int count = Integer.parseInt(scanner.nextLine());
  9.  
  10. double evenSum = 0;
  11. double evenMax = Integer.MIN_VALUE ;
  12. double evenMin = Integer.MAX_VALUE;
  13. double oddSum = 0;
  14. double oddMax = Integer.MIN_VALUE;
  15. double oddMin = Integer.MAX_VALUE;
  16.  
  17. for (int i = 1; i <= count ; i++) {
  18.  
  19. double num = Double.parseDouble(scanner.nextLine());
  20.  
  21. if(i % 2 == 0){
  22. evenSum += num;
  23.  
  24. if(num > evenMax){
  25. evenMax = num;
  26. }
  27. if(num < evenMin){
  28. evenMin = num;
  29. }
  30. }else{
  31. oddSum+= num;
  32.  
  33. if(num > oddMax){
  34. oddMax = num;
  35. }
  36. if(num < oddMin){
  37. oddMin = num;
  38. }
  39. }
  40. }
  41.  
  42. DecimalFormat format = new DecimalFormat("#.##########"); //1.574897785405497
  43.  
  44. System.out.print("OddSum=" + format.format(oddSum) + "," + "\n");
  45. if(oddMin == Integer.MAX_VALUE){
  46. System.out.println("OddMin=No,");
  47. }else{
  48. System.out.print("OddMin=" + format.format(oddMin) + ","+ "\n");
  49. } if(oddMax == Integer.MIN_VALUE){
  50. System.out.println("OddMax=No,");
  51. }else{
  52. System.out.print("OddMax=" + format.format(oddMax) + "," + "\n");
  53. }
  54.  
  55. System.out.print("EvenSum=" + format.format(evenSum) + ",\n");
  56. if(evenMin == Integer.MAX_VALUE){
  57. System.out.println("EvenMin=No,");
  58. }else{
  59. System.out.print("EvenMin=" + format.format(evenMin) + ",\n");
  60. } if(evenMax == Integer.MIN_VALUE){
  61. System.out.println("EvenMax=No");
  62. }else{
  63. System.out.printf("EvenMax=" + format.format(evenMax) + "\n");
  64. }
  65.  
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement