也许外面的人感觉很友好,会觉得这个脑筋急转弯很有趣..但我觉得也许我开始让自己感到困惑。
其目的是使用循环算法计算完成所有过程所需的时间。我让它提示用户输入时间量,然后它要计算多少个进程。从那里,我抛出一个基于有多少进程来分配进程到达时间和突发时间的 for 语句。
对于那些不熟悉的人来说,时间量子是在切换到下一个之前它将处理多少个周期,爆发是完成该过程需要多少个周期,当然到达时间是在它之前完成了多少个周期到达。简单的算法,但它是为了显示 CPU 的调度方式。如果有人能提供帮助,那就太棒了!我迷路了。我想在 C# 中做到这一点,但我的编程技能在 C# 中还不够。
我遇到的两个问题是在我的 if 语句中,我开始迷失自己,无论出于何种原因,在使用 dif < parrive.get[ii] 或 dif < parrive.get(ii) 甚至编译时都会出错在我的 if 语句的开头将 parrive.get[ii] 分配给另一个变量并使用另一个变量(如图所示)......
import java.io.*;
import java.util.*;
public class Thread{
public Thread() {
inputexecute();
}
public void inputexecute(){
Scanner x = new Scanner(System.in);
int xx = 0;
String choice = null;
ArrayList parrive = new ArrayList();
ArrayList pburst = new ArrayList();
while (true){
System.out.println("Enter the time quantum: ");
int quant = x.nextInt();
System.out.println("Enter the number of processes: ");
int pnum = x.nextInt();
for( int i=0; i<pnum; i++)
{
System.out.println("Enter the arival for p"+i+": ");
int arrive = x.nextInt();
parrive.add(arrive);
System.out.println("Enter the burst time: ");
int burst = x.nextInt();
pburst.add(burst);
}
int dif;
for(int ii=0; ii < pnum; ii++)
{
int asw == parrive.get[ii];
if (asw < quant)
{
dif = quant - asw;
}
if (quant < asw)
{
asw = asw - quant;
}
if (dif > 0)
{
}
}
} /* end while*/
} /* end exec input*/
} /* class thread */