Advertisement
igrilkul

Odd/Even position

Nov 6th, 2017
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. import java.util.Scanner;
  2. //import java.text.DecimalFormat;
  3.  
  4. public class loopers
  5. {
  6.   public static void main(String[] Args)
  7.   {
  8.     Scanner a=new Scanner(System.in);
  9.     int z=Integer.parseInt(a.nextLine());
  10.     //DecimalFormat format = new DecimalFormat("#.#");
  11.     //format.setDecimalSeparatorAlwaysShown(false);
  12.     double emax=-100000000.00;
  13.     double emin=100000000.00;
  14.     double omax=-100000000.00;
  15.     double omin=100000000.00;
  16.     double u=0;
  17.     double p=0;
  18.    
  19.     for(int i=1;i<=z;i++)
  20.     {
  21.       double y=Double.parseDouble(a.nextLine());
  22.      if(i%2==0)
  23.      {
  24.        p=p+y;
  25.        
  26.        if(y>emax)
  27.          emax=y;
  28.        if(y<emin)
  29.          emin=y;
  30.        
  31.      }
  32.       else
  33.       {
  34.       u=u+y;
  35.      
  36.     if(y>omax)
  37.      omax=y;
  38.   if(y<omin)
  39.      omin=y;
  40.         }
  41.     }
  42.  
  43.    
  44.    
  45.      System.out.printf("Oddsum=%.0f,",u);
  46.      
  47.      if(omax==-100000000.00){
  48.       System.out.println("Oddmin=No,");
  49.       System.out.println("Oddmax=No,");
  50.       }else{System.out.printf("Oddmin=%.0f,",omin);
  51.       System.out.printf("Oddmax=%.0f,",omax);}
  52.      
  53.       System.out.printf("Evensum=%.0f,",p);
  54.   if(emax==-100000000.00){
  55.       System.out.println("Evenmin=No,");
  56.       System.out.println("Evenmax=No,");
  57.       }else{System.out.printf("Evenmin=%.0f,",emin);
  58.       System.out.printf("Evenmax=%.0f,",emax);}
  59.  
  60.  
  61.     //System.out.println("Oddmin="+(decimalFormat.format(omin))+","); вади грешка
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement