Sự khác nhau giữa việc trả về giá trị của hàm khi truyền tham số vào và việc sử dụng biến static trực tiếp trong hàm?

Mọi người cho mình hỏi sự khác nhau giữa việc trả về giá trị của hàm khi truyền tham số vào và việc sử dụng biến static trực tiếp trong hàm của java ạ. có hai chương trình tương tự nhau mà mình dùng static lại không ra kết quả là sao ạ??? ví dụ bài toán người du lịch:

public class newTSP {
    static int n;
    static int[][] cost;
    static boolean invited[];
    static int[]  curr;
    static int curr_cost;
    static int[] result;
    static int cmin=Integer.MAX_VALUE, best=Integer.MAX_VALUE, sum;
    
    static void initInvited(){
        for (int i = 0; i < n; i++) {
            invited[i]=false;
        }
    }
    
    static void initCost(){
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                        System.out.println("Input distance from city " + i + " to city " + j + " :");
                        cost[i][j] = sc.nextInt();
                        //cost[j][i] = cost[i][j];
                        if (cmin > cost[i][j]) {
                            cmin = cost[i][j];
                        }
                    } else {
                        cost[i][j] = 0;
                    }
            }
        }
    }
    
    static void accept(){
        
        sum = curr_cost + cost[curr[n-1]][curr[0]];
        if(sum<best){
            System.arraycopy(curr, 0, result,0, n);
            best=sum;
        }
    }
    
    //co dinh thanh pho xuat phat laf thanh pho 0
    static void Try(int i){
        for (int j = 1; j < n-1; j++) {
            if(!invited[j]){
                curr[i]=j;
                invited[j]=true;
                curr_cost = curr_cost + cost[curr[i-1]][curr[i]];
                if(i == (n-1)) accept();
                else if(curr_cost + (n-i+1)*cmin<best) Try(i+1);
                curr_cost=curr_cost-cost[curr[i-1]][curr[i]];
                invited[j]=false;
                
            }
        }
    }
    
    static void display(){
        System.out.println("Tour:\t");
        for (int i : result) {
            System.out.print(i + "\t");
        }
    }
    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("input number of city: ");
        n=sc.nextInt();
        
        cost=new int [n][n];
        invited=new boolean[n];
        curr=new int[n];
        result=new int[n];
        
        
        initInvited();
        initCost();
        Try(1);
        display();
        System.out.println("best cost: "+best);
    }
}

mong mọi người giúp đỡ!!!

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?