Sign in with
Sign up | Sign in
Your question

Java Display Help

Last response: in Applications
Share
May 4, 2012 12:58:53 PM

Hi i want to display a set of data and such as doubles but the zero`s after the decimal is messing everything up.How can i display this using system.out.println or printf without rounding of the doubles. . I am using System.out.printf. Heres the code


void SchoolArrays(){
String Schools[] = {"Sutherland: ","Waterkloof: ","GlenhighSc: ","Riverhighc: ","Soweto high "};
double Metal[] = {56.5,32.4,103.2,46.7,82.3};
double Glass[] = {12.2,67.9,35.6,72.2,89.9};
double Paper[] = {95,19.1,9.3,53.6,29.1};
double Other[] = {32.4,43.2,0.5,39.4,13.2};
//Question 9
for(int x = 0;x<Metal.length;x++){
OverAllWeights = OverAllWeights + Metal[x] + Glass[x] + Paper[x] + Other[x];
}
System.out.printf("%s %10s %5s %5s %5s %5s","SchoolName","Metal","Glass","Paper","Other","Totals");
for(int x = 0;x<Schools.length;x++){
Total[x] = Metal[x] + Glass[x] + Paper[x] + Other[x];
System.out.printf("%s %5.0f %5.0f %5.0f %5.0f %8.0f","\n"+Schools[x],Metal[x],Glass[x],Paper[x],Other[x],Total[x]);
}
for(int x = 0;x<Schools.length;x++){
metal = metal + Metal[x];
glass = glass + Glass[x];
paper = paper + Paper[x];
other = other+Other[x];
}
System.out.printf("%s %11.0f %5.0f %5.0f %5.0f %7.0f","\n"+"Totals:",metal,glass,paper,other,OverAllWeights);
}
}


And The output
SchoolName Metal Glass Paper Other Totals
Sutherland: 57 12 95 32 196
Waterkloof: 32 68 19 43 163
GlenhighSc: 103 36 9 1 149
Riverhighc: 47 72 54 39 212
Soweto high 82 90 29 13 214
Totals: 321 278 206 129 934


THanks

More about : java display

May 22, 2012 6:42:24 PM

Thanks it worked
m
0
l
!