Created
September 30, 2021 02:47
-
-
Save uluumbch/8799f50ddeb4fbddf9642e26a892c53f to your computer and use it in GitHub Desktop.
program dadu sederhana menggunakan java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package praktikum3.soal1; | |
import java.util.Random; | |
public class Dadu { | |
public Dadu() { | |
acakNilai(); | |
} | |
int acakNilai() { | |
Random nilai = new Random(); | |
return 1 + nilai.nextInt(6); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package praktikum3.soal1; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.Scanner; | |
public class DaduMain { | |
public static void main(String[] args) { | |
Dadu dadu = new Dadu(); | |
Scanner sc = new Scanner(System.in); | |
List<Integer> kumpulanAngka = new LinkedList<>(); | |
int n = sc.nextInt(); | |
int total = 0; | |
for (int i = 0; i < n; i++) { | |
kumpulanAngka.add(dadu.acakNilai()); | |
System.out.println("Dadu ke-" + (1 + i) + " bernilai " + kumpulanAngka.get(i)); | |
total += kumpulanAngka.get(i); | |
} | |
System.out.println("Total nilai dadu keseluruhan " + total); | |
sc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Soal