Recitation_IntroToRandom

Recitation_IntroToRandom - if (Math.random()...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.Random; i public class Recitation_IntroToRandom{ public int dieRoll(){ int dieRoll = (int)(6 * Math.random()) + 1; return dieRoll; } public int twoDiceRoll1(){ int dieRoll1 = dieRoll(); int dieRoll2 = dieRoll(); int sum = dieRoll1 + dieRoll2; return sum; } public int twoDiceRoll2(){ int twoDiceRoll = (int)(11 * Math.random()) + 2; return twoDiceRoll; } public boolean winTheRaffle(){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (Math.random() < 0.5 ) return true; else return false; } public int dieRoll2(){ Random gen = new Random(); int dieRoll = gen.nextInt(6) + 1; return dieRoll; } public static void main(Stringargs){ Recitation_IntroToRandom rec = new Recitation_IntroToRandom(); for (int i = 0; i < 30; i++) System.out.println(rec.dieRoll()); } }...
View Full Document

Ask a homework question - tutors are online