forked from BITOCTA/Process-Scheduling-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSJF.java
More file actions
30 lines (25 loc) · 797 Bytes
/
SJF.java
File metadata and controls
30 lines (25 loc) · 797 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
package process_scheduling_algorithm;
public class SJF {
public static double SJF(int[] mas) {
double avg = 0;
System.out.println("");
System.out.println("Let's calculate the average waiting time using process_scheduling_algorithm.SJF algorithm");
int t;
for (int i = 0; i < mas.length; i++) {
for (int j = i + 1; j < mas.length; j++) {
if (mas[j] < mas[i]) {
t = mas[i];
mas[i] = mas[j];
mas[j] = t;
}
}
}
for (int i = 0; i < mas.length; i++) {
for (int k = i; k > 0; k--) {
avg += mas[k - 1];
}
}
double favg = avg / mas.length;
return favg;
}
}