Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name:Omar Natour
- * Date: 11/30/2015
- * Course Number: Csc-111-D01
- * Course Name: Intro To Java
- * Problem Number: HW# 16
- * Email:Ojnatour0001@student.stcc.edu
- * Short Description of the Problem: Write a short program to find 5 + 1 random numbers for a lottery drawing.
- */
- import java.util.Arrays;
- import java.util.Scanner;
- import java.lang.Math;
- public class LuckForLife {
- public static void main(String args[]) {
- final String TITLE = "Lucky For Life Lottery Nubmers Generator";
- final String CONTINUE_PROMPT = "Do this again? [y/N] ";
- System.out.println("Welcome to " + TITLE);
- Scanner sc = new Scanner(System.in);
- String doover;
- do {
- output();
- System.out.print(CONTINUE_PROMPT);
- doover = sc.nextLine();
- } while (doover.equalsIgnoreCase("Y"));
- sc.close();
- System.out.println("Thank you for using " + TITLE);
- }
- public static void output() {
- int[] x1 = GenNum();
- int luckB = (int) (Math.random() * 44 + 1);
- Arrays.sort(x1);
- System.out.print("Your Lucky For Life Cash numbers are:");
- for (int i = 0; i < 5; i++)
- System.out.printf("%3d", x1[i]);
- System.out.printf("\n" + "Your Lucky Ball Number is:" + "%3d", luckB);
- System.out.println();
- }
- public static int[] GenNum() {
- int x[] = new int[5];
- boolean dup = true;
- for (int i = 0; i < x.length; i++)
- x[i] = (int) (Math.random() * 44 + 1);
- while (dup) {
- if (x[0] == x[1] || x[0] == x[2] || x[0] == x[3] || x[0] == x[4]) {
- x[0] = (int) (Math.random() * 44 + 1);
- dup = true;
- } else if (x[1] == x[2] || x[1] == x[3] || x[1] == x[4]) {
- x[1] = (int) (Math.random() * 44 + 1);
- dup = true;
- } else if (x[2] == x[3] || x[2] == x[4]) {
- x[2] = (int) (Math.random() * 44 + 1);
- dup = true;
- } else if (x[3] == x[4]) {
- x[3] = (int) (Math.random() * 44 + 1);
- dup = true;
- } else
- dup = false;
- }
- return x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement