2017-06-25 54 views
-1

該程序從它比較的用戶中恢復出兩組數字,然後如果第一個比較大pointA接收一個等級,如果不是pointB接收一個等級並且它繼續直到最後一個數字。我的問題是,我無法打印最終結果,因爲我在program.how中可以使用反射 或任何其他方法將其打印出來,因此pointA,pointB的等級因爲靜態方法而不同?使用反射調用主類中的靜態方法

public class Solution { 
 
    static int[] solve(int a0, int a1, int a2, int b0, int b1, int b2){ 
 
     int pointA=0; 
 
    int pointB=0; 
 
     int FristArray[]={a0,a1,a2}; 
 
     int scoundArray[]={b0,b1,b2}; 
 
     for(int x=0;x<=FristArray.length;x++) 
 
     for(int y=0;x<=scoundArray.length;y++) 
 
      if (x>y){ 
 
       pointA+=1; 
 
      } 
 
     else if(x<y){ 
 
      pointB+=1; 
 
     } 
 
     int points[]={pointA,pointB}; 
 
     return points; 
 
    } 
 

 
    public static void main(String[] args) { 
 
     Scanner in = new Scanner(System.in); 
 
     int a0 = in.nextInt(); 
 
     int a1 = in.nextInt(); 
 
     int a2 = in.nextInt(); 
 
     int b0 = in.nextInt(); 
 
     int b1 = in.nextInt(); 
 
     int b2 = in.nextInt(); 
 
     int[] result = solve(a0, a1, a2, b0, b1, b2); 
 
     for (int i = 0; i < result.length; i++) { 
 
       System.out.print(result[i]+"i want to print it here"); 
 
     } 
 
     System.out.println(""); 
 
     
 

 
    }

+0

問題到底是什麼? – EJP

+1

問題是無限循環。仔細看一下'solve'中的內部循環:'for(int y = 0; x <= scoundArray.length; y ++)' –

+1

'static'與它有什麼關係?什麼讓你認爲思考能解決它? – EJP

回答

0

你的問題是第二個循環:不

for(int y=0;x<=scoundArray.length;y++) 

for(int y=0;y<=scoundArray.length;y++) 

變化X到Y

public class Solution { 

      static int[] solve(int a0, int a1, int a2, int b0, int b1, int b2){ 
        int pointA=0; 
       int pointB=0; 
        int FristArray[]={a0,a1,a2}; 
        int scoundArray[]={b0,b1,b2}; 
        for(int x=0;x<=FristArray.length;x++) 
        for(int y=0;y<=scoundArray.length;y++) 
         if (x>y){ 
          pointA+=1; 
         } 
        else if(x<y){ 
         pointB+=1; 
        } 
        int points[]={pointA,pointB}; 
        return points; 
       } 

     public static void main(String[] args) { 
      // TODO Auto-generated method stub 
       Scanner in = new Scanner(System.in); 
       System.out.println("Enter the values : (Master rsl)"); 
       int a0 = in.nextInt(); 
       int a1 = in.nextInt(); 
       int a2 = in.nextInt(); 
       int b0 = in.nextInt(); 
       int b1 = in.nextInt(); 
       int b2 = in.nextInt(); 
       int[] result = solve(a0, a1, a2, b0, b1, b2); 
       for (int i = 0; i < result.length; i++) { 
         System.out.print(result[i]+ " " +i+ " want to print it here"); 
       } 
       System.out.println(""); 


     } 

    } 
+0

這是錯誤,我改變了它,但我仍然有錯誤,我嘗試打印它,我如何嘗試打印結果是static.solve-錯誤是非法的表達式開始 –

+0

請給我看源代碼 –