public static void main(String[] args) { Proces[] pArr = new Proces[5]; pArr[0] = new Proces("P0", new int[]{7, 5, 3}, new int[]{0, 1, 0}, new int[]{7, 4, 3}); pArr[1] = new Proces("P1", new int[]{3, 2, 2}, new int[]{2, 0, 0}, new int[]{1, 2, 2}); pArr[2] = new Proces("P2", new int[]{9, 0, 2}, new int[]{3, 0, 2}, new int[]{6, 0, 0}); pArr[3] = new Proces("P3", new int[]{2, 2, 2}, new int[]{2, 1, 1}, new int[]{0, 1, 1}); pArr[4] = new Proces("P4", new int[]{4, 3, 3}, new int[]{0, 0, 2}, new int[]{4, 3, 1}); BlankerAlgorithm ba = new BlankerAlgorithm(new int[]{3, 3,2}); ba.dispath(pArr); } 将以上代码改为控制台输入
时间: 2024-03-16 20:47:57 浏览: 52
C#中static void Main(string[] args) 参数示例详解
可以将以上代码改为控制台输入,如下所示:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[][] max = new int[5][3];
int[][] allocation = new int[5][3];
int[][] need = new int[5][3];
for (int i = 0; i < 5; i++) {
System.out.print("请输入进程" + i + "的最大需求量(max),格式为x y z,空格隔开:");
max[i][0] = scanner.nextInt();
max[i][1] = scanner.nextInt();
max[i][2] = scanner.nextInt();
System.out.print("请输入进程" + i + "的已分配量(allocation),格式为x y z,空格隔开:");
allocation[i][0] = scanner.nextInt();
allocation[i][1] = scanner.nextInt();
allocation[i][2] = scanner.nextInt();
for (int j = 0; j < 3; j++) {
need[i][j] = max[i][j] - allocation[i][j];
}
}
System.out.print("请输入可用资源量(available),格式为x y z,空格隔开:");
int[] available = new int[]{scanner.nextInt(), scanner.nextInt(), scanner.nextInt()};
BlankerAlgorithm ba = new BlankerAlgorithm(available);
Proces[] pArr = new Proces[5];
for (int i = 0; i < 5; i++) {
pArr[i] = new Proces("P" + i, max[i], allocation[i], need[i]);
}
ba.dispath(pArr);
}
}
```
运行程序后,会依次提示输入每个进程的最大需求量、已分配量和可用资源量,然后输出进程的执行顺序。
阅读全文