Zufall2.java |
1 /** 2 * 183.592 Programmierpraxis TU Wien WS2014/15 H.Moritsch 3 */ 4 public class Zufall2 { 5 public static void main(String[] args) { 6 7 int anzahl80 = 0; 8 int anzahl20 = 0; 9 10 for (int i = 0; i < 100; i++) { 11 12 double r = Math.random(); 13 System.out.println(r); 14 15 if ( r < 0.80 ) { 16 17 // in 80% aller Fälle: 18 19 System.out.println(" 80%"); 20 anzahl80++; 21 } 22 else { 23 24 // in den restlichen 20% der Fälle: 25 26 System.out.println(" 20%"); 27 anzahl20++; 28 } 29 30 } 31 32 System.out.println("80%: " + anzahl80); 33 System.out.println("20%: " + anzahl20); 34 35 36 } 37 38 } 39