Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我的for循环跳过第一步_Java - Fatal编程技术网

Java 为什么我的for循环跳过第一步

Java 为什么我的for循环跳过第一步,java,Java,这是我的密码 import java.util.*; public class lozanosjfver21 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("enter the processes"); int nop=sc.nextInt(); int z=nop; int table1[][]

这是我的密码

import java.util.*;

public class lozanosjfver21 {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    System.out.println("enter the processes");

    int nop=sc.nextInt();
    int z=nop;
    int table1[][] = new int[z][6];
    int table2[][] = new int[z][6];

    int total = 0;
    boolean con[] = new boolean[z];
    boolean fin[] = new boolean[z];
    boolean lowest[] = new boolean[z];

    for(int a=0;a<z;a++) {
      System.out.print("Input ARRIVAL TIME and BURST TIME for process"+(a+1)+":");
      StringTokenizer st = new StringTokenizer(sc.nextLine());
      int b=1;
      while(st.hasMoreTokens()) {
        table1[a][b] = Integer.parseInt(""+st.nextToken());
        table2[a][b] = table1[a][b];
        b++;
      }
      table1[a][0] = (a+1);
      table2[a][0] = table1[a][0];
      total += table1[a][2];
      con[a] = false;
      fin[a] = false;
      lowest[a] = false;
    }
    //System.out.println(""+total);
    String str[] = new String[total];

    for(int c=0;c<total;c++) {
      /*
       * determines if a row should be considered
       * (! done and within the current time)
       */
      for(int d=0;d<z;d++) {
        if (table1[d][1]<=c&&!fin[d]) {
          con[d] = true;
        }
      }

      /*
       * determines the first low value
       * (the basis for the determining the
       * lowest value in each loop)
       */
      int low=0;
      for(int j=0;j<z;j++) {
        if(con[j]) {
          low = table1[j][2];
          break;
        }
      }

      /*
       * determines the lowest value among
       * the values considered
       */
      for(int k=0;k<z;k++) {
        if(table1[k][2]<low&&con[k]) {
          low = table1[k][2];
        }
      }

      /*
       * marks the lowest
       */
      for(int l=0;l<z;l++) {
        if(table1[l][2]==low) {
          lowest[l] = true;
          break;
        }
      }

      //this part does all the actions
      for(int f=0;f<z;f++) {
        if(lowest[f]) {
          table1[f][2] -= 1;
          if(table1[f][2]==0) {
            fin[f] = true;
            str[c] = ""+(f+1);
            break;
          }
        }
      }

      if(str[c]==null) str[c] = "0";

      //clearing
      for(int p=0;p<z;p++) {
        lowest[p] = false;
        con[p] = false;
      }
    }

    for(int n=0;n<total;n++) {
      if(str[n]!="0") {
        table2[Integer.parseInt(str[n])-1][5] = n+1;
      }
    }
    for(int t=0;t<nop;t++) {
      table2[t][4] = table2[t][5] - table2[t][1];
      table2[t][3] = table2[t][4] - table2[t][2];
    }

    System.out.println("\nP\tAT\tBT\tWT\tTT");
    for(int x=0;x<z;x++) {
      System.out.println(""+table2[x][0]+"\t"+table2[x][1]+"\t"+table2[x][2]+"\t"+table2[x][3]+"\t"+table2[x][4]+"\t");
    }
}

我只是在这里猜测,你代码上的格式几乎是不可读的

数组从0开始,因此:

int b=1;
可能需要更改为

int b = 0;

您可能需要格式化您的代码!看起来糟透了!!为什么您要在已经提供了
nextInt()
扫描仪上使用
StringTokenizer
?您是否打算跳过
b=0
?除了第一个过程外,输出确实会显示……对于p1,它会将所有内容显示为0您需要修复代码格式并进行更多解释。
int b = 0;