2016-11-13 135 views
-3

我有一個代碼, 我們需要找到範圍變量在我已經評論過的piratical點。 但我懷疑args是否在範圍變量?java中的範圍變量

這裏是代碼:

public class HelloWorld { 
    public static int foo(int num) { 
     int other_num = 2; 
     // num , other_num 
     return num % other_num; 
    } 

    public static void main(String[] args) { 
     int odd = 0; 

     int x = 13; 
     for (int value = 0; value < x; value++) { 
      // value , odd , x 
      boolean local_odd = false; 
      int r = foo(value); 
      if (r == 1) { 
       // value , odd , x , local_odd, r 
       local_odd = true; 
      } else { 
       int div = value/2; 
       System.out.println(div +" divides "+ value); 
       // value , odd , x , local_odd, r , div 
      } 
      if (local_odd) { 
       odd++; 
      } 
     } 
     System.out.println(odd+" odd numbers smaller than "+x); 
     // odd , x 
    } 
} 
+1

你的問題並不清楚和適當。請詳細說明 – Rehman

+0

對不起,但是_「在角度寫下範圍變量」_是不可理解的。 「Piratical」意思是「與海盜有關」,這可能不是你想要的。 –

+0

「範圍變量」表示什麼?海事組織是無稽之談。每個變量_has_的範圍在可見和有效的地方。 – Heri

回答

0

args範圍是在main()。你可以檢查this了。 args是一個方法參數,因此只在main()中有效,如果這就是你要求的。