Advertisement
Krassi_Daskalova

OddEvenPosition

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