gpt4 book ai didi

java - 使用循环算法来计算所需时间

转载 作者:行者123 更新时间:2023-12-01 15:56:03 25 4
gpt4 key购买 nike

也许有人感觉很友好,并且会觉得这个脑筋急转弯很有趣..但我觉得也许我开始困惑了自己。

其目的是使用循环算法计算完成所有进程所需的时间。我让它提示用户输入时间量,然后提示用户要计算多少个进程。从那里,我根据进程的数量抛出一个 for 语句来分配进程到达时间和突发时间。

对于那些不熟悉的人来说,时间量是在切换到下一个之前要处理多少个周期,突发是完成该过程需要多少个周期,当然到达时间是有多少个周期在到达之前完成。算法很简单,但是它是为了展示CPU是如何调度的。如果有人能提供帮助那就太好了!我很失落。我想用 C# 来做这件事,但我的 C# 编程技能不足以做到这一点。

我遇到的两个问题都在我的 if 语句中,我开始迷失自己,并且无论出于何种原因,在使用 diff < 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 */

最佳答案

您的错误是您使用了相等运算符 (==) 而不是赋值

                            int asw == parrive.get[ii];

应该是

                            int asw = parrive.get[ii];

关于java - 使用循环算法来计算所需时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5037010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com