-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCouponNum.java
37 lines (35 loc) · 1.09 KB
/
CouponNum.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package Bridgelabz.com;
import java.util.Scanner;
public class CouponNum {
static String[] couponArray;
static String generateCoupon() {
String str = "";
for(int i = 0; i <= 4; i++) {
int randomDigit = (int)(Math.random()*10);
str = str + randomDigit;
}
String checkedDuplicacy = checkCoupons(str);
return checkedDuplicacy;
}
static String checkCoupons(String newCoupon) {
int check = 0;
for(String existing : couponArray)
if (newCoupon == existing)
check++;
if (check != 0)
generateCoupon();
return newCoupon;
}
public static void main(String[] args) {
String str = "";
System.out.print("How many coupon numbers you want? : ");
Scanner sc=new Scanner(System.in);
int coupons = sc.nextInt();
couponArray = new String[coupons]; // array
for(int i = 0; i < coupons; i++) {
str = generateCoupon();
System.out.println("Coupon Number "+(i+1)+" : "+str);
}
sc.close();
}
}