Java程序无法读取命令

时间:2017-12-06 14:48:57

标签: java

所以,我正在制作一个循环程序并完成所有工作,但是当我编译并运行我的代码时,它会在某些时候停止读取命令,但编译器显示它正在运行。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author User1
 */
public class Testing {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        try {
            DataInputStream in=new DataInputStream(System.in);
            int i,j,k,n, quantum;
            Double burst,sum=0.0;
            Double awt = 0.0, atat = 0.0;
            ArrayList<Double> bt = new ArrayList<Double>();
            ArrayList<Double> wt = new ArrayList<Double>();
            ArrayList<Double> tat = new ArrayList<Double>();
            ArrayList<Double> a = new ArrayList<Double>();
            System.out.println("enter num of processes : ");
            n=Integer.parseInt(in.readLine());
            for(i=0; i<n; i++)
            {
                burst = Double.parseDouble(in.readLine());
                bt.add(burst);
            } // for loop
            System.out.println("Array List bt : " + bt);
            System.out.println("Time Quantum : ");
            quantum = Integer.parseInt(in.readLine());
            a.addAll(bt);
            System.out.println("Array List a : " + a);
            for (i=0; i<bt.size(); i++)
            {
                wt.add(0.0);
            } // for loop
            System.out.println("Array List wt : " + wt);

            do
            { // do starts
                for(i=0; i<bt.size()-1; i++)
                {
                    if(bt.get(i) > quantum)
                    {
                        bt.set(i, bt.get(i) - quantum);
                        System.out.println("Array List bt after subtracting quantum: " + bt);

                        for(j=0; j<bt.size()-1; j++)
                        {
                            if(j != i && bt.get(j) != 0)
                            {
                                wt.add(wt.get(j) + quantum);
                                System.out.println("Array List wt after adding quantum and setting it to index of process : " + wt);
                            } // if statement
                        } // nested for loop
                    } // if statement. 

                    else 
                    {
                        for(j=0; j<bt.size(); j++)
                        {
                            if(j != i && bt.get(j) != 0)
                            {
                                wt.set(j, wt.get(j)+bt.get(j));
                            } // if statement
                            bt.add(0.0);
                        } // for loop
                    } // else statement
                } // for loop

                for(k=0; k<a.size(); k++)
                {
                    sum = sum + a.get(k);
                } // for loop
            } // do ends

            while(sum!=0);
            {
                for(i=0; i<a.size(); i++)
                {
                    tat.add(wt.get(i) + a.get(i));
                } // for loop

                for (i=0; i<a.size(); i++)
                {
                    awt = awt + wt.get(i);
                } // for loop
                for(i=0; i<a.size(); i++)
                {
                    atat = atat + tat.get(i);
                } // for loop
            } // while loop
            System.out.println("awt = " +awt+ "\n atat = "+atat);
        } // main
        catch (IOException ex) {
            Logger.getLogger(Testing.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

} // class

它应该生成awt&amp;输出中的atat。 我认为循环的某种方式变成了无限循环,这就是程序无法读取其他命令的原因。

输出:

enter num of processes : 
4

 enter burst time of 4processes : 
15
7
19
18
Array List bt : [15.0, 7.0, 19.0, 18.0]
Time Quantum : 
7
Array List a : [15.0, 7.0, 19.0, 18.0]
Array List wt : [0.0, 0.0, 0.0, 0.0]
Array List bt after subtracting quantum: [8.0, 7.0, 19.0, 18.0]
Array List wt after adding quantum and setting it to index of process : [0.0, 0.0, 0.0, 0.0, 7.0]
Array List wt after adding quantum and setting it to index of process : [0.0, 0.0, 0.0, 0.0, 7.0, 7.0]

this is the output i get

0 个答案:

没有答案