import java.io.InputStreamReader;import java.io.*;
public class SJF_Non_Preemptive
{
public static void main(String args[])
{
int arrival[],burst[],i,n=0;
try
{
System.out.println("Enter no of jobs: ");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(in.readLine());
arrival =new int[n];
burst=new int[n];
for(i=0;i<n;i++)
{
System.out.println("Enter "+i+" job arrival time: ");
arrival[i]=Integer.parseInt(in.readLine());
System.out.println("Enter "+i+" job burst time :");
burst[i]=Integer.parseInt(in.readLine());
if(arrival[i]<0||burst[i]<=0)
throw new IOException("e");
}
float answer[]=new float[2];
answer=calculate(arrival,burst);
System.out.println("Avg wait Time: "+answer[0]);
System.out.println("Avg turn around time :"+answer[1]);
}
catch(Exception e)
{
System.out.println("Some error occured");
}
}
static float[] calculate(int arrival[],int burst[])
{
int i=0,no_of_jobs=0,nextsmall=0,time=0;
float answer[]=new float[2];
answer=new float[2];
answer[0]=0;
answer[1]=0;
no_of_jobs=arrival.length;
for(i=0;i<no_of_jobs;i++)
{
nextsmall=min(arrival,burst,time);
answer[0]+=(float)(time-arrival[nextsmall]);
answer[1]+=(float)(time+burst[nextsmall]-arrival[nextsmall]);
time+=burst[nextsmall];
}
answer[0]/=no_of_jobs;
answer[1]/=no_of_jobs;
return answer;
}
static int min(int arrival[],int burst[],int time)
{
int nextsmall=0,i=0;
for(i=0;i<arrival.length;i++)
{
if(time>arrival[i])
{
if(burst[i]<burst[nextsmall])
nextsmall=i;
}
else
break;
}
return nextsmall;
}
}
SJF_Non_Preemptive.zip_it
版权申诉
154 浏览量
2022-09-23
09:39:58
上传
评论
收藏 830B ZIP 举报
邓凌佳
- 粉丝: 65
- 资源: 1万+
最新资源
- 基于matlab实现字符识别的参考程序,用所用的字体识别率挺高,部分手写的也能识别,但是还不能识别扭曲和倾斜的字符 .rar
- 基于matlab实现指纹识别系统 包括数据库导入、图像选择识别、帮助功能、识别图像可视、gabor滤波可视,实现界面操作.rar
- 基于matlab实现指纹识别,利用gabor滤波器,提取指纹特征,只能呢读取bmp图像.rar
- 基于matlab实现于数字图像相关方法中散斑质量评价
- 基于matlab实现遗传算法和佳点集遗传算法的基本思想和不同点,用遗传算法测试一标准函数 佳点集算法测试一标准函数
- tensorflow-gpu-2.5.1-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-gpu-2.5.0-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-gpu-2.5.2-cp39-cp39-manylinux2010-x86-64.whl
- 内含方正小标宋简体、仿宋-Gb2312、黑体、楷体、宋体,五个公文常用字体
- 记忆卡牌游戏源码及可运行文件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈