java - Decimal Format? -


i wrote lab supposed flip 2 coins 500 times , count how many times heads , tails flipped , supposed calculate percentage tenth. remember template decimal formatting, forgot how use it. can help? program follows:

import java.util.scanner; import java.text.decimalformat;  public class lab97a {         public static void main(string [] args)         {           scanner input = new scanner(system.in);         decimalformat accuracy=new decimalformat("0.0");          dice coin;         int numcoin;         int numheads;         int numtails;         int count;         double percentageheads;         double percentagetails;          coin=new dice(2);         numheads=0;         numtails=0;          system.out.println("a coin tossed 500 times. results asfollows: ");          (count=1;count<=500;count=count+1)         {             numcoin=coin.roll();             if (numcoin==1)             {                 numheads+=1;             }             if (numcoin==2)             {                 numtails+=1;             }         }         percentageheads=numheads/5;         percentagetails=numtails/5;         system.out.println("heads flipped "+numheads+" times, "+percentageheads+"%.");         system.out.println("tails flipped "+numtails+" times, "+percentagetails+"%");         } } 

it looks need format accuracy e.g. accuracy.format(percentageheads). see numberformat.format(double) decimalformat extends.


Comments