-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputGetter.java
More file actions
45 lines (36 loc) · 830 Bytes
/
Copy pathInputGetter.java
File metadata and controls
45 lines (36 loc) · 830 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Scanner;
/**
* Classe per la gestione dell'input
*/
public class InputGetter {
private double[] input;
public InputGetter(double[] input) {
if (input == null) {
readInput();
} else {
this.input = input;
}
}
/**
* lettura array da standard input
*/
public void readInput() {
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
sc.close();
// elimino spazi e punto finale
line = line.replaceAll("\\s","");
line = line.substring(0, line.length() - 1);
String[] splittedLine = line.split(",");
input = new double[splittedLine.length];
for (int i = 0; i < splittedLine.length; i++) {
input[i] = Double.valueOf(splittedLine[i]);
}
}
public double[] getInput() {
return input;
}
public void setInput(double[] input) {
this.input = input;
}
}