24 7/26/2017 9:45:04 PM


:
package CoinToss;

import java.util.Random;

public class CoinToss {

    public static int tossACoin() {
        Random rand = new Random();
        int nextRandom = rand.nextInt();
        /*
         * System.out.println(nextRandom);
         * System.out.println(Math.abs(nextRandom));
         * System.out.println(Math.abs(nextRandom) % 2);
         */
        int toss = Math.abs(nextRandom) % 2;
        System.out.println(toss);
        return toss;
    }

    public static void main(String[] args) {
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
        tossACoin();
    }
}
 
:
run:
0
0
0
0
1
1
1
1
1
1
0
0
BUILD SUCCESSFUL (total time: 0 seconds)