首页 新闻 赞助 找找看

请问这是哪里出问题了??

0
[待解决问题]
 1 class Solution {
 2     
 3     void sortIntegers(int[] A) {
 4         int n;
 5         for(int a = 0; a<A.length-2; a++)
 6         {
 7             int b;
 8             for(b = a ; b<A.length-2; b++)
 9                {
10                 if(A[b]>A[b+1])
11                 n=b+1;     
12                    
13                } 
14                System.out.print(A[n]);
15         }
16     }
17 }
18 
19 public class Sort
20 {
21     public static void main (String[] arg)
22     {
23         Solution S = new Solution();
24         int[]A = {3,2,1,4,5};
25         S.Solution(A);
26         System.out.print(S);
27     }
28 }

鱼尾巴的主页 鱼尾巴 | 菜鸟二级 | 园豆:202
提问于:2018-05-25 18:20
< >
分享
所有回答(2)
0

S.Solution(A);是什么鬼?
你这段代码编译都不会通过的

、熙和 | 园豆:1508 (小虾三级) | 2018-05-25 18:33

就是不知道怎么把这个数组赋给Solution,能解答一下吗?

支持(0) 反对(0) 鱼尾巴 | 园豆:202 (菜鸟二级) | 2018-05-25 18:35

class Solution {

  void sortIntegers(int[] A) {
      int n;
      for(int a = 0; a<A.length-2; a++)
      {
          int b;
          for(b = a ; b<A.length-2; b++)
             {
             if(A[b]>A[b+1])
             n=b+1;

            }
            System.out.print(A[n]);
     }
 }

}
int n 没有初始值; 因为在编译阶段就能确定, 如果不符合if条件, System.out.print(A[n]);就会异常

支持(0) 反对(0) 、熙和 | 园豆:1508 (小虾三级) | 2018-05-25 18:36

@鱼尾巴:
Solution对象里面没有Solution方法吧, 你应该是s.sortIntegers(A)吧?

支持(0) 反对(0) 、熙和 | 园豆:1508 (小虾三级) | 2018-05-25 18:37

@、熙和: 函数名都写错了。。。

支持(0) 反对(0) 鱼尾巴 | 园豆:202 (菜鸟二级) | 2018-05-25 18:42

@、熙和: 

int[]A = {3,2,1,4,5};
Solution S = new Solution(A);

这样也不行啊,为什么呢?

 

sort.java:24: 错误: 无法将类 Solution中的构造器 Solution应用到给定类型;
Solution S = new Solution(A);
^
需要: 没有参数
找到: int[]
原因: 实际参数列表和形式参数列表长度不同

支持(0) 反对(0) 鱼尾巴 | 园豆:202 (菜鸟二级) | 2018-05-25 18:48

@鱼尾巴: ....... Solution S = new Solution(A); 你又没有带参的构造, 还是好好看看书吧

支持(0) 反对(0) 、熙和 | 园豆:1508 (小虾三级) | 2018-05-25 20:12
0

。类名是solution,sortintegers才是你定义的函数

xuqiong | 园豆:204 (菜鸟二级) | 2018-05-30 01:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册