2015-07-04 54 views
-2

我正在嘗試編寫代碼,它需要3個輸入值10 4 3.您可以看到kdx值爲0.當它調用函數hello時,qdx的值將更改爲11,但是它應該是0.並且返回值也是11.你知道它爲什麼會發生嗎?函數的返回值

import java.util.Scanner; 
import java.io.FileNotFoundException; 

public class test1 { 

    private static final int FORWARD = 1; 
    private static final int BACKWARDS = -1; 
    private static Scanner scn = new Scanner(System.in); 

    public static void main(String args[]) throws FileNotFoundException { 

     int N = scn.nextInt(); 
     int k = scn.nextInt(); 
     int m = scn.nextInt(); 
     while (N != 0) { 
      boolean[] offQueue = new boolean[N]; 
      int offCount = 0; 
      int kdx = 0; 
      int mdx = N - 1; 
      kdx = hello(k, offQueue, kdx, FORWARD); 
      System.out.println(kdx); 
     } 
    } 

    private static int hello(int q, boolean[] offQueue, int qdx, int direction) { 
     return qdx;//Problem is here 
    } 
} 
+0

您可以使用IDE *中提供的*調試模式來檢查這些 –

+1

http://ideone.com/vQQbBP我無法複製它.. –

+0

您是否可能省略了'hello'的某些代碼? –

回答

0

我無法重現您的問題。你確定在運行它時使用了你的最新版本嗎?你也可以嘗試用Eclipse調試你的應用程序。

+1

這應該是一條評論 – maskacovnik