Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int count = Integer.parseInt(scanner.nextLine());
- double evenSum = 0;
- double evenMax = Integer.MIN_VALUE ;
- double evenMin = Integer.MAX_VALUE;
- double oddSum = 0;
- double oddMax = Integer.MIN_VALUE;
- double oddMin = Integer.MAX_VALUE;
- for (int i = 1; i <= count ; i++) {
- double num = Double.parseDouble(scanner.nextLine());
- if(i % 2 == 0){
- evenSum += num;
- if(num > evenMax){
- evenMax = num;
- }
- if(num < evenMin){
- evenMin = num;
- }
- }else{
- oddSum+= num;
- if(num > oddMax){
- oddMax = num;
- }
- if(num < oddMin){
- oddMin = num;
- }
- }
- }
- DecimalFormat format = new DecimalFormat("#.##########"); //1.574897785405497
- System.out.print("OddSum=" + format.format(oddSum) + "," + "\n");
- if(oddMin == Integer.MAX_VALUE){
- System.out.println("OddMin=No,");
- }else{
- System.out.print("OddMin=" + format.format(oddMin) + ","+ "\n");
- } if(oddMax == Integer.MIN_VALUE){
- System.out.println("OddMax=No,");
- }else{
- System.out.print("OddMax=" + format.format(oddMax) + "," + "\n");
- }
- System.out.print("EvenSum=" + format.format(evenSum) + ",\n");
- if(evenMin == Integer.MAX_VALUE){
- System.out.println("EvenMin=No,");
- }else{
- System.out.print("EvenMin=" + format.format(evenMin) + ",\n");
- } if(evenMax == Integer.MIN_VALUE){
- System.out.println("EvenMax=No");
- }else{
- System.out.printf("EvenMax=" + format.format(evenMax) + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement