Java examples for Algorithm:Random
rolling 2 dices one is the user and the other is the computer
import java.util.Scanner; public class Random2 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); }/*from www.j a v a 2 s . c o m*/ { int dice1; int dice2; dice1 = (int) (Math.random() * 11) + 1; dice2 = (int) (Math.random() * 11) + 1; if (dice1 > dice2) System.out.println(" You won "); else if (dice1 == dice2) System.out.println(" Tie "); else if (dice1 < dice2) System.out.println(" You lost "); } }