fluctuacion.java 794 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
public class fluctuacion {
    public static void main(String[] args) {
     
        String numeros = "20,23,25,30,22,21,26";
        String[] resultadoSplit = numeros.split(",");
        double fluc;
        int aux1=0,mayor=0,index=0;
        for (String itemSplit : resultadoSplit) {
            System.out.println(itemSplit);
        }

        for(int i=0; i<6;i++){
            aux1=(Integer.parseInt(resultadoSplit[i])-Integer.parseInt(resultadoSplit[i+1]));
          if(aux1<1){
              aux1=aux1*-1;
          } 
            if(aux1>mayor){
               mayor=aux1;
               index=i;
           }
        }

        fluc=(double)mayor/Integer.parseInt(resultadoSplit[index])*100;
        System.out.println("La mayor fluctuacion es "+fluc+" "+index);
        

    }
}