Java :: Aufgabe #280 :: Lösung #1
2 Lösungen
#280
Häufigkeit einer 6 beim Würfeln?!
Anfänger - Java
von DragStar
- 06.04.2020 um 08:34 Uhr
Verfassen Sie ein Programm, welches 25.000 mal, jeweils so lange das Würfeln mit einem Würfel simuliert, bis eine 6 erscheint.
Auszugeben ist, wie oft man dabei schlimmstenfalls würfeln musste.
Auszugeben ist, wie oft man dabei schlimmstenfalls würfeln musste.
#1
von TheFirstLuc (280 Punkte)
- 13.05.2020 um 20:40 Uhr
Java-Code
import java.util.Scanner; public class Dice { public static void main(String[] args) { int rolls = 0; int six = 0; Scanner sc = new Scanner(System.in); System.out.print("How many rolls: "); rolls = sc.nextInt(); for(int i = 0; i < rolls; i++) { if((int)(Math.random()*7) == 6) {six++;} } System.out.println("You rolled "+six+" times a 6"); } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1