Advertisement
elena_tasheva

Untitled

Oct 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OddEvenPosition {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7. int n = Integer.parseInt(scanner.nextLine());
  8. double sumOdd = 0;
  9. double sumEven = 0;
  10. double maxEven = -1000000000.0;
  11. double minEven = 1000000000.0;
  12. double maxOdd = -1000000000.0;
  13. double minOdd = 1000000000.0;
  14.  
  15.  
  16. for (int i = 1; i <=n ; i++) {
  17. double number = Double.parseDouble(scanner.nextLine());
  18.  
  19. if (i%2==0){
  20. sumEven+=number;
  21. if (number>maxEven){
  22. maxEven=number;
  23. }
  24. if (number<minEven){
  25. minEven=number;
  26. }}
  27. else{
  28. sumOdd+=number;
  29. if(number>maxOdd){
  30. maxOdd=number;}
  31. if (number<minOdd){
  32. minOdd=number;
  33. }
  34. }
  35.  
  36. }
  37.  
  38. System.out.printf("OddSum=%.2f,%n", sumOdd);
  39. if (minOdd!=1000000000.0){
  40. System.out.printf("OddMin=%.2f,%n", minOdd);}
  41. else{
  42. System.out.println("OddMin=No,");
  43. }
  44. if (maxOdd!=-1000000000.0){
  45. System.out.printf("OddMax=%.2f,%n", maxOdd);}
  46. else{
  47. System.out.println("OddMax=No,");
  48. }
  49. System.out.printf("EvenSum=%.2f,%n", sumEven);
  50. if (minEven!=1000000000.0){
  51. System.out.printf("EvenMin=%.2f,%n", minEven);}
  52. else{
  53. System.out.println("EvenMin=No,");
  54. }
  55. if (maxEven!=-1000000000.0){
  56. System.out.printf("EvenMax=%.2f%n", maxEven);}
  57. else{
  58. System.out.println("EvenMax=No");
  59. }
  60.  
  61.  
  62.  
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement