Skip to content

Commit

Permalink
#2 make random method
Browse files Browse the repository at this point in the history
  • Loading branch information
G-ONL committed Mar 23, 2019
1 parent 66d9101 commit cfa5033
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.util.Random;


public class Main {

public static void main(String args[]) {
Expand All @@ -8,9 +11,25 @@ public static void main(String args[]) {
}
}

public static int[] createRandomNumber() {
public static boolean isDuplicate(int[] computerNumber, int i) {
for (int j = 0; j < i; j++) {
if (computerNumber[i] == computerNumber[j]) {
return true;
}
}
return false;
}

return null;
public static int[] createRandomNumber() {
Random rand = new Random();
int[] computerNumber = new int[3];
for (int i = 0; i < 3; i++) {
computerNumber[i] = rand.nextInt(9) + 1; // [1-9]
if (isDuplicate(computerNumber, i)) {
i--;
}
}
return computerNumber;
}

public static int[] Input() {
Expand Down

0 comments on commit cfa5033

Please sign in to comment.