-
Notifications
You must be signed in to change notification settings - Fork 904
Expand file tree
/
Copy pathplaygame.java
More file actions
31 lines (25 loc) · 863 Bytes
/
playgame.java
File metadata and controls
31 lines (25 loc) · 863 Bytes
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
package baseballgame;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class playgame {
Scanner scanner = new Scanner(System.in);
public List<Integer> player_num() {
System.out.println("Enter Number : ");
List<Integer> player_num = new ArrayList<>();
String input = String.valueOf(scanner.nextInt());
for(int i=0; i<input.length(); i++){
int digit = Character.getNumericValue(input.charAt(i));
if (!player_num.contains(digit)) {
player_num.add(Integer.parseInt(String.valueOf(digit)));
}
}
Length_exception(input);
return player_num;
}
public void Length_exception(String s){
if(s.length() != 3) {
throw new IllegalArgumentException("Not a three digit number");
}
}
}