Täringustatistika
Allikas: Lambda
public class Taring { public static void main(String[] args){ int i; int count; int minsum=2,maxsum=12; double d1,d2; int t1,t2; int sum=0; double avg; int[] stat; stat = new int[maxsum+1]; count=Integer.parseInt(args[0]); System.out.println ("Taring: tehakse "+count+" viset"); // kogume visked massiivi stat for(i=0; i<count; i++) { d1=(Math.random()*6)+1; t1=(int)d1; d2=(Math.random()*6)+1; t2=(int)d2; stat[t1+t2]++; } // trykime visete massiivi stat for(i=1;i<=maxsum;i++) { System.out.print(stat[i]+" "); } System.out.println("\n\n"); // trykime visete massiivi tulpadena int rida,tulp; for(rida=1;rida<=10;rida++) { System.out.print(rida+":" ); for(tulp=1;tulp<=maxsum;tulp++) { if (stat[tulp]>=rida*10000) System.out.print("** "); else System.out.print(" "); } System.out.println(); } System.out.println(); } }