-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
35 lines (30 loc) · 927 Bytes
/
Utils.java
File metadata and controls
35 lines (30 loc) · 927 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
import java.util.Random;
import java.util.Scanner;
public class Utils {
public static final Random generator = new Random();
public static final String NEW_LINE = System.getProperty("line.separator");
public static final String readLine() {
Scanner reader = new Scanner(System.in);
return reader.nextLine();
}
public static final int readInt() {
Scanner reader = new Scanner(System.in);
return reader.nextInt();
}
/**
* The method String repeat is availabe in Java 11+
* Some students still have Java 8 (or less) so we
* will implement this method directly for backwards
* compatibility
* @param str The string the repeat
* @param numTimes How often to repeat
*/
protected static String repeat(String str, int numTimes)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < numTimes; i++) {
sb.append(str);
}
return sb.toString();
}
}