-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermonaceIssues.java
More file actions
49 lines (43 loc) · 1.25 KB
/
permonaceIssues.java
File metadata and controls
49 lines (43 loc) · 1.25 KB
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
46
47
48
49
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class PerformanceIssues {
public static void main(String[] args) {
String result = "";
for (int i = 0; i < 10000; i++) {
result += "a";
}
System.out.println(result);
List<Integer> list = new ArrayList<>();
for (int i = 0; i < 10000; i++) {
list.add(i);
}
for (int i = 0; i < 10000; i++) {
Random random = new Random();
int num = random.nextInt();
System.out.println(num);
}
int count = 0;
for (int i = 2; i < 10000; i++) {
if (isPrime(i)) {
count++;
}
}
System.out.println("Number of primes: " + count);
try (FileReader fileReader = new FileReader("largefile.txt")) {
int ch;
while ((ch = fileReader.read()) != -1) {
System.out.print((char) ch);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static boolean isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i < n; i++) {
if (n % i == 0) return false;
}
return true;
}
}