I got this array of values
float Guy_A [] = {194,180,221,432,820,200,312,177,190, 70};
And i wrote this "for" for a total values
for (int i=0; i < Guy_A.length;i++)
{ A += Guy_A[i];}
And after that i want to make a mid point divition using this
float pcnt_a = A * 100 /vt;
//the vt is declared above as a float and it value is 10489
After that i run the file using this commands:
System.out.println("Guy A has "+A+" votes");
System.out.println("His Average is"+df.format(pcnt_a)+" %\n");
The problem is that the first line returns '2796.0' (the actual total) but the second one only returns 0.00 '%' //the df.format is 0.00, for skip other 6 decimal numbers.
I have tried with double and int, but it still shows 0.0. Can some one please explain me what can i do with this thing...
//Full code:
public class Estadisticas { //float A = 2796;
float Candidato_A [] = {194,180,221,432,820,200,312,177,190, 70};
float Candidato_B [] = { 48, 20, 90, 50, 61,100, 99, 87, 77,122};
float Candidato_C [] = {206,320,140,821,946,155,501,075,005,12};
float Candidato_D [] = { 45, 16, 20, 14, 18,355,122,178,501,117};
float Candidato_E [] = {155,501,075,178,501,117,700,55,78,12};
float vt = 10489;
boolean no_win;
public void totalVotos(){
for (int i=0; i<Candidato_A.length;i++){
A += Candidato_A[i]; }
for (int i=0; i<Candidato_B.length;i++){
B += Candidato_B[i]; }
for (int i=0; i<Candidato_C.length;i++){
C += Candidato_C[i]; }
for (int i=0; i<Candidato_D.length;i++){
D += Candidato_D[i]; }
for (int i=0; i<Candidato_E.length;i++){
E += Candidato_E[i];
}
}
float A; float B; float C; float D; float E;
float pcnt_a = A * 100 /vt;
float pcnt_b = B * 100 /vt;
float pcnt_c = C * 100 /vt;
float pcnt_d = D * 100 /vt;
float pcnt_e = E * 100 /vt;
public void imprimeDatos(){
DecimalFormat df= new DecimalFormat("0.00");
System.out.println("\n\n -- Estadisticas de las elecciones --\n");
System.out.println("El Candidato A obtuvo "+A+" votos");
System.out.println("Su Porcentaje de votos fue de "+df.format(pcnt_a)+" %\n"); System.out.println("El Candidato B obtuvo "+B+" votos");
System.out.println("Su Porcentaje de votos fue de"+df.format(pcnt_b)+" %\n");
System.out.println("El Candidato C obtuvo"+C+" votos");
System.out.println("Su Porcentaje de votos fue de"+df.format(pcnt_c)+" %\n");
System.out.println("El Candidato D obtuvo"+D+" votos");
System.out.println("Su Porcentaje de votos fue de"+df.format(pcnt_d)+" %\n");
System.out.println("El Candidato E obtuvo"+E+" votos");
System.out.println("Su Porcentaje de votos fue de"+df.format(pcnt_e)+" %\n");
if(A>B && A>C && A>D && A>E){
System.out.println("-- El Candidato A obtuvo la mayor cantidad de votos --\n");
} else{
if(B>A && B>C && B>D && B>E){
System.out.println("-- El Candidato B obtuvo la mayor cantidad de votos --\n");
} else{
if(C>B && C>A && C>D && C>E){
System.out.println("-- El Candidato C obtuvo la mayor cantidad de votos --\n");
} else{
if(D>B && D>C && D>A && D>E){
System.out.println("-- El Candidato D obtuvo la mayor cantidad de votos --\n");
} else{
if(E>B && E>C && E>D && E>A){
System.out.println("-- El Candidato E obtuvo la mayor cantidad de votos --\n");
}
}
}
}
}
}
Sorry for the spanish, right now i need this for a university proyect.