-2
我是新來的java和有這個問題一整天。 我想實現一個FCFS調度程序,我被卡住的地方要求用戶輸入字符串形式的進程數。解析對象數組到一個函數
還聲明瞭一個類型的進程數組,並且創建了一個函數,將字符串切成表示突發時間和到達時間的整數。
到目前爲止好,但是當我嘗試打印值不順心的事
public class Process {
private static int BT;
private static int AT;
Process(){
AT=0;
BT=0;
}
Process(int burst, int arrival){
BT=burst;
AT=arrival;
}
//GETS and SETS
public static void setBT(int burst){
BT=burst;
}
public int getBT(){
return BT;
}
public static void setAT(int arrival){
AT=arrival;
}
public int getAT(){
return AT;
}
}
public static void main(String[] args) {
Process pArray[]=new Process[10];
System.out.println("Choose the Scheduler \n 1-FCFS");
Scanner input =new Scanner(System.in);
int schedulerType = input.nextInt();
switch(schedulerType){
case 1:
System.out.println("You have choosen FCFS Scheduler");
System.out.println("Now enter the Process each seperated by a semicolon where the first number is the Burst time, and the second is the Arrival time separated by a comma");
System.out.println("EX: 1,2;3,4;");
stringcutter(pArray);
System.out.println(pArray[0].getBT());
System.out.println(pArray[0].getAT());
break;
default:
System.out.println("You have entered a wrong scheduler Type");
}
public static void stringcutter(Process[] processArray){
String pString="1,2;3,4;";
String[] array=pString.split(";");
int processesNumber=array.length;
for(int i=0;i<processesNumber;i++){
String[] oneProcess =array[i].split(",");
int burstTime = Integer.parseInt(oneProcess[0]);
int arrivalTime = Integer.parseInt(oneProcess[1]);
processArray[i] =new Process(burstTime,arrivalTime);
}
}
}
我預計輸出爲數字1和2,相反,我越來越3和4
也運行調試器,但沒有找到p roblem。
@RAZ_Muh_Taz問題是,我使用一個以上的靜態變量 Thansk對您有所幫助。 – AhmedWael