程序正在运行,但没有输出,程序也没有终止 [英] The program is running but there's no output and the program is not terminated

查看:157
本文介绍了程序正在运行,但没有输出,程序也没有终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行多级队列调度



- 优先级== 1 || priority == 2在队列1中使用循环法

- priority == 3 || priority == 4使用队列2中的先到先得(fcfs)

- 优先级> 4是在队列3中使用fcfs



我尝试过的代码是不完整的但是我尝试运行以查看前3个输入是否有效,但是有一个未知的错误(我不知道错误调用了什么)程序运行的地方但它没有显示任何输出而且程序没有终止。



流程AT BT优先

p0 0 6 3

p1 1 4 3

p2 5 6 1



我尝试过:



I'm trying to do multilevel queue scheduling where

- priority==1 || priority==2 is using round robin in queue 1
- priority==3 || priority==4 is using first come first serve (fcfs) in queue 2
- priority > 4 is using fcfs in queue 3

the code that I've tried is incomplete but I try to run to see whether it works or not for the first 3 inputs, but there is an unknown error (I don't know what the error called) where the program run but it doesn't show any output and the program is not terminated.

process AT BT priority
p0 0 6 3
p1 1 4 3
p2 5 6 1

What I have tried:

public void sortMultilevel(int[] AT, int[] BT, int[] prio, int[] status, int TP)
	{
		int i=0, current=AT[i], j, test;
		while(TP!=0)
		{
			if(prio[i]==1 || prio[i]==2)
			{
				System.out.println("Queue 1:");
				System.out.print("p" + p[i] + " from " + current + " to ");
				// if(nonew())
				// {}
				// else {
				System.out.println(current+quantum);
				BT[i] = BT[i]-quantum;
				status[i]=1;
				current+=quantum;
				break;
				// }
			}
			else if(prio[i]==3 || prio[i]==4)
			{
				System.out.println("Queue 2:");
				System.out.print("p" + p[i] + " from " + AT[i] + " to ");
				// if(nonew())
				// {
					
				// }
				// else
				// {
					test=0;
					for(j=0; j<TP; j++)
					{
						if(AT[j]<current+BT[i])
						{
							if(prio[j]<prio[i])
							{
								System.out.println(AT[j]);
								BT[i] = BT[i]-(AT[j]-current);
								status[i]=1;
								current=AT[j];
								test=1;
								i=j;
								break;
							}
							else
							status[j]=1;
						}
						
					}
				// }
			}
		} // close while loop
	}

推荐答案

Quote:

程序正在运行,但是没有输出,程序也没有终止

The program is running but there's no output and the program is not terminated



如何看你的节目表演以了解正在发生的事情。



你的代码表现不像你期待,或者你不明白为什么!



有一个几乎通用的解决方案:一步一步地在调试器上运行你的代码,检查变量。

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它不知道你的是什么cpde应该这样做,它没有找到错误,只是通过向你展示发生了什么来帮助你。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。

调试器 - 维基百科,免费的百科全书 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows /jdb.html [ ^ ]

https: //www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]

调试器仅显示您的代码正在执行的操作,您的任务是与什么进行比较应该这样做。


What about watching you program performing to understand what is going on.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your cpde is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.


这篇关于程序正在运行,但没有输出,程序也没有终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆