1. Dice

public class DiceRandom {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a = 0;
		int b = 0;

		while (a + b != 5) {

			a = (int) (Math.random() * 6) + 1;
			b = (int) (Math.random() * 6) + 1;
			System.out.println(a + "," + b);
		}
	}

}

2. Lottery

import java.util.Random;

public class LotteryRandom {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		// Making an Array
		Random ran = new Random();
		int[] Lottery = new int[6];

		// Picking random numbers
		int i;
		for (i = 0; i < 6; i++) {
			Lottery[i] = ran.nextInt(45) + 1;
			for (int j = 0; j < i; j++) {
				if (Lottery[i] == Lottery[j])
					i--;
				break; 
			}
			System.out.println("Lottery number : " + Lottery[i]);
		}

	}

}

 

'Codes & Projects' 카테고리의 다른 글

HTML / Javascript / JSP ) Sign up Form2  (0) 2022.08.28
HTML / Javascript /JSP ) Bulletin Board  (0) 2022.08.28
Javascript/ JSP/ HTML ) Log in form  (0) 2022.08.27
Java) Finding Maximum value  (0) 2022.08.25
jQuery/ JSP) Sign up Form  (0) 2022.08.24

+ Recent posts