使用反射

时间:2017-06-25 00:16:27

标签: java arrays reflection static-methods

这个程序从它比较的用户恢复2组数字然后如果第一个是更大的点A接收一个等级,如果不是pointB接收一个等级并且它继续直到最后一个数字。我的问题是我无法打印pointA,pointB的等级的最终结果,因为我在program.how中有静态方法,我可以用反射打印它 或任何其他方法?

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("");
        

    }

1 个答案:

答案 0 :(得分:0)

你的问题是第二个循环:不是

for(int y=0;y<=scoundArray.length;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("");


        }

    }

将x更改为y

{{1}}